走进.NET

吸收.NET的力量

导航

留言板制作(三)



  一,页面设计
     此页面的控件有:3个Label,其中有个Label是用来显示留言的,它的Text属性加入了HTML代码2个Button,2个Datagrid 。其风格可以自己设计 (如下图:)
 
  二,代码编写
     1,页面加载
       Dim aa As String = ConfigurationSettings.AppSettings("Mycon")
       Dim conn As SqlConnection = New SqlConnection(aa)
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim str As String
        conn.Open()
        Dim cmd As New SqlCommand("select * from savely where id=" & WebForm1.aaa, conn)
         Dim reader As SqlDataReader
        reader = cmd.ExecuteReader
        While reader.Read
            str = "<table width='550' height='84' border='0'>" & _
                   "<tr bgcolor='#66ff99'>" & _
                       "<td height='25' colspan='2'>标题:" & reader.Item("tilte") & "</td> " & _
                   "</tr>" & _
                   "<tr bgcolor='#FFaa88'>" & _
                       "<td width='148' height='25'>发言人:" & reader.Item("name") & " </td>" & _
                       "<td width='392' bgcolor='#FFaa88'>发言时间:" & reader.Item("time1") & "</td>" & _
                   "</tr>" & _
                   "<tr bgcolor='#aaffaa'>" & _
                       "<td height='26' colspan='2'>内容:" & reader.Item("content") & "</td>" & _
                    "</tr>" & _
                  "</table>"           ‘这段代码是HTML代码,是将留言显示在Label中,其效果如上图
            Label1.Text = str    
        End While
        reader.Close()
        conn.Close()
        show()
      End Sub

    Sub show()   ‘这个方法是读取该留言相关的回复内容,这样的好处是避免程序过与集中,给维护带来不便
        If Not IsPostBack Then
            Dim da As New SqlDataAdapter("select name,content,time1 from huifuly where id=" & WebForm1.aaa, conn)
            Dim ds As New DataSet
            da.Fill(ds, "huifuly")
            DataGrid1.DataSource = ds.Tables("huifuly").DefaultView
            DataGrid1.DataBind()
        End If
    End Sub
  
   2,回复
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Redirect("HFLY.aspx")  ’显示回复界面
    End Sub
 
    3,返回
   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Response.Redirect("WebForm1.aspx")  ‘回到哦留言板界面
    End Sub

    4,Datagrid的翻页
     Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        DataGrid1.CurrentPageIndex = e.NewPageIndex
        show()
    End Sub

     下一节进入留言板的回复页面设计和代码编写

posted on 2006-09-15 13:13  JiTaXiaoZi  阅读(2877)  评论(5编辑  收藏  举报