走进.NET

吸收.NET的力量

导航

留言板制作(一)


 一,数据库设计
此留言板子只需要两个表,一个是保存留言信息(savely),其数据字段是(Id,name,time1,content(内容),tilte),另一个表的保存回复信息(huifuly),其数据字段是(Id,name,time1,content(内容)),savel表的Id是自动编号产生的,他标志记录的唯一性,huifuly表中的Id和savely
是对应的,假如,savely中的某条记录的Id是3,那么huifuly中的所有Id是3的记录是savely中Id为3的记录对应留言回复记录。
二,留言板的设计
控件有:一个Label1,button1,datagrid1。 其中Datagrid1中有一个超级链接列,传送savely的ID,下一页面通过ID来获取相应的数据(如图:)

代码设计:
   1,页面加载
     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim aa As String = ConfigurationSettings.AppSettings("Mycon")    'Mycon在Web.config中定义了
        Dim conn As SqlConnection = New SqlConnection(aa)                   
        Dim da As New SqlDataAdapter("select name,tilte,time1 from savely", conn)
        Dim ds As New DataSet
        da.Fill(ds, "savely")
        DataGrid1.DataSource = ds.Tables("savely").DefaultView
        DataGrid1.DataBind()
     End Sub

   2,“我要留言”进入留言板
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Redirect("LY.aspx")     ’进入留言板页面
    End Sub

   3,datagrid中的翻页
      Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As        System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles DataGrid1.PageIndexChanged
        DataGrid1.CurrentPageIndex = e.NewPageIndex    ‘指定新的页数
        Dim aa As String = ConfigurationSettings.AppSettings("Mycon")
        Dim conn As SqlConnection = New SqlConnection(aa)
        Dim da As New SqlDataAdapter("select name,tilte,time1 from savely", conn)
        Dim ds As New DataSet
        da.Fill(ds, "savely")
        DataGrid1.DataSource = ds.Tables("savely").DefaultView
        DataGrid1.DataBind()
    End Sub
 
  4,选择标题进入查看留言
      Public Shared aaa As Int16 ‘定义个共享的变量,存储选中标题的Id
    Private Sub DataGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.SelectedIndexChanged
        aaa = (DataGrid1.CurrentPageIndex * 4) + DataGrid1.SelectedIndex + 1  '计算Id
        Response.Redirect("HF.aspx")
    End Sub

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

posted on 2006-09-14 20:33  JiTaXiaoZi  阅读(6397)  评论(21编辑  收藏  举报