A simple BBS demo including(CRUD) - 5

8. Create a webform named "Read" in the website.

Read.aspx

========

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Read.aspx.cs" Inherits="Read" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Read</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr>
            <td>Title: </td>
            <td><asp:Label ID="lblTitle" runat="server" Width="327px"></asp:Label></td>
        </tr>
        <tr>
            <td>Writer: </td>
            <td>
                <asp:Label ID="lblWriter" runat="server"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;
                WriteDate: <asp:Label ID="lblWriteDate" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>Content: </td>
            <td><asp:TextBox ID="txtContent" runat="server" Height="227px" TextMode="MultiLine" ReadOnly="true"
                    Width="327px"></asp:TextBox></td>
        </tr>
    </table>
    <p>
        <asp:Button ID="btnUpdate" Text="Update" runat="server"
            onclick="btnUpdate_Click" />&nbsp;&nbsp;&nbsp;
        <asp:Button ID="btnDelete" Text="Delete" runat="server"
            onclick="btnDelete_Click" />&nbsp;&nbsp;&nbsp;
        <asp:Button ID="btnReturn" runat="server" Text="List"
            onclick="btnReturn_Click" />&nbsp;&nbsp;&nbsp;
        <a href="javascript:history.back()">BACK</a>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <cc1:ConfirmButtonExtender ID="ConfirmButtonExtender1" ConfirmText="Do you really wannt delete it?" TargetControlID="btnDelete" runat="server">
        </cc1:ConfirmButtonExtender>
    </p>
    </div>
    </form>
</body>
</html>

===========================================================================================

Read.aspx.cs

===========

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Read : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int id = Convert.ToInt32(Request.Params["ID"]);
            BLL bbs = new DAL().GetDataByID(id);

            lblTitle.Text = bbs.Title;
            lblWriter.Text = bbs.Writer;
            lblWriteDate.Text = bbs.WriteDate.ToString("yyyy-MM-dd") ;
            txtContent.Text = bbs.Content;
        }
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        new DAL().DeleteDataByID(Convert.ToInt32(Request.Params["ID"]));
        Response.Redirect("List.aspx");
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Response.Redirect("Update.aspx?ID="+Convert.ToInt32(Request.Params["ID"]));
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Redirect("List.aspx");
    }
}

 

posted @ 2009-01-13 23:43  OOK  阅读(106)  评论(0编辑  收藏  举报