首页 > 开发 > 综合 > 正文

利用c#制作简单的留言板 (3)

2024-07-21 02:20:21
字体:
来源:转载
供稿:网友
菜鸟学堂:
显示列表list.aspx
<%@ page language="c#" codebehind="list.cs" autoeventwireup="false" inherits="notpage.list" %>
<html><head>
    <meta name="generator" content="microsoft visual studio 7.0">
    <meta name="code_language" content="c#"></head>
  <body>
    
    <form method="post" runat="server">

     </form><a href = "addtopic.aspx">发表留言</a><br>
    <table width="90%" height="1" border="0" cellspacing="2" cellpadding="2" id=liuyan>
    <tr>
        <td>主题</td>
        <td>留言人</td>
        <td>留言时间</td>
    </tr>
    
        <asp:label id="n_tdtitle" runat=server></asp:label>
    
</table>

  </body></html>
namespace notpage
{
    using system;
    using system.collections;
    using system.componentmodel;
    using system.data;
    using system.drawing;
    using system.web;
    using system.web.sessionstate;
    using system.web.ui;
    using system.web.ui.webcontrols;
    using system.web.ui.htmlcontrols;

        


    /// <summary>
    ///    summary description for list.
    /// </summary>
    public class list : system.web.ui.page
    {
        protected system.web.ui.webcontrols.label n_tdtitle;
    
    public list()
    {
        page.init += new system.eventhandler(page_init);
        }

        protected void page_load(object sender, eventargs e)
        {
            if (!ispostback)
            {
                //
                // evals true first time browser hits the page
                //
            }
        }

        protected void page_init(object sender, eventargs e)
        {
            //
            // codegen: this call is required by the asp+ windows form designer.
            //
            initializecomponent();
            init_tdtitle();
    

        }
        

        /// <summary>
        ///    required method for designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void initializecomponent()
        {
            this.load += new system.eventhandler (this.page_load);
        }
        
        protected void init_tdtitle()
        {
             initializecomponent();
            //
            // codegen: this call is required by the asp+ windows form designer.
            //
            try
            {    
                notepage np = new notepage();

                arraylist arrtopic = np.gettopiclist();
            
                for ( int i = 0 ; i < arrtopic.count  ; i ++)
                {    
                    notepage objtopic = (notepage)arrtopic[i] ;
                    string str ="<tr><td><a href = showtopic.aspx?id="+objtopic.id.tostring()+">" + objtopic.title.tostring() + "</a></td>";
                    str = str +"<td>" + objtopic.author.tostring()+"</td>";
                    str = str +"<td>" + objtopic.adddate.tostring()+"</td></tr>";
                    n_tdtitle.text = str  + n_tdtitle.text;
                }
            }
            catch(exception e)
            {
                throw(new exception("取得贴子列表出错:" + e.tostring())) ;
            }

        }
    }
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表