首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

ASP.NET Web Forms 留言板實作(四):檢視單篇留言

     編輯:關於C語言

前端頁面 (showTopic.aspx)

使用 ASP.NET Web Forms 模式,繼承 notpage.showTopic 類別:

<%@ Page Language="c#" Codebehind="showTopic.cs" AutoEventWireup="false" Inherits="notpage.showTopic" %>
<html><head>
<meta name="GENERATOR" content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" content="C#"></head>
<body>
<form method="post" runat="server">
<p align="center"><font color="red"><b>檢視留言</b></font></p><br>
<p align="left"><font color="blue">
留言主題:<asp:Label id="n_tdtitle" runat="server" ForeColor="Black"></asp:Label><br>
留言時間:<asp:Label id="n_tdAdddate" runat="server" ForeColor="Black"></asp:Label><br>
留言人:<asp:Label id="n_tdAuthor" runat="server" ForeColor="Black"></asp:Label><br>
留言內容:<asp:Label id="n_tdContent" runat="server" ForeColor="Black"></asp:Label>
</font></p>
</form>
</body></html>

後端程式碼 (showTopic.cs)

namespace notpage
{
    using System;
    using System.Web.UI.WebControls;

    public class showTopic : System.Web.UI.Page
    {
        protected Label n_tdAuthor, n_tdContent, n_tdAdddate, n_tdtitle, n_ttitle;

        public showTopic()
        {
            Page.Init += Page_Init;
        }

        protected void Page_Load(object sender, EventArgs e) { }

        protected void Page_Init(object sender, EventArgs e)
        {
            int int_ID = Convert.ToInt32(Request.QueryString["ID"]);
            notepage np = new notepage();
            notepage objNp = np.GetTopic(int_ID);

            n_tdtitle.Text = objNp.Title;
            n_tdContent.Text = objNp.Content;
            n_tdAuthor.Text = objNp.Author;
            n_tdAdddate.Text = objNp.AddDate.ToString();

            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.Load += Page_Load;
        }
    }
}

關鍵說明

  • 透過 Request.QueryString["ID"] 取得留言編號。
  • 呼叫資料存取類別 notepage.GetTopic() 取得資料實體。
  • 將資料繫結至 asp:Label 控制項顯示。
  • 採用 VS.NET 7.0 產生的設計器程式碼模式(InitializeComponent)。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved