( 10 )添加表格并添加服务器控件。在图 92-10 中圆角方框①所示的位置添加一个 3 行一列的表格,在表格的第 1 行中添加“ asp :文本框”,设置 ID 为“ title ”;在表格的第 2 行中添加“ asp :文本框”,设置 ID 为“ myblog ”;在表格的第 3 行中添加“ asp :按钮”,设置 ID 为“ refer ”,文本为“发表”,结果如图 92-15 中圆角方框所示。 ( 11 )在“ <script runat="server"> ”中定义“ page_load ”过程,该过程的代码如下所述。 Sub page_load(Src As Object, E As EventArgs) If Session("myblogtm")<>nothing Then MyCalendar.TodaysDate=session("myblogtm") End If panel2.visible=false If MyblogData.recordcount > 0 Then blogreplac.Enabled = True blogdelet.Enabled = True Else blogreplac.Enabled = False blogdelet.Enabled = False End If End Sub (读者可打开【光盘】|【源文件】|【实例 92 】|【 92.4.txt 】文件,直接复制) 程序说明: 代码中除了定义日历控件的“ TodaysDate ”(日历控件的“今天”日期)属性为变更后的日期外,还要定义当目前日期下没有博客随笔时,“编辑”、“删除”链接按钮无效。 ( 12 )定义“ blogreplac_Click ”过程,用于响应【编辑】链接按钮的“ OnClick ”事件。 Sub blogreplac_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim string1, string2 As String string1 = MyblogData.FieldValue("title", Nothing) string2=MyblogData.FieldValue("myblog", nothing) titlereplace.Text = string1 myblogreplace.Text=string2 panel2.Visible = True panel1.Visible = False End Sub ( 13 )定义“ blogupdate_Click ”过程,用于响应【更新】链接按钮的“ OnClick ”事件。 Sub blogupdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim cpConn, Cpstring As String Dim conn As OleDbConnection Dim Cpadapter As OleDbDataAdapter Dim Cpdat As System.Data.DataSet Dim dt As DataTable cpConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("dat\bad.mdb") conn = New OledbConnection(cpConn) Cpstring = "select * from myblog where myblogID=" & MyblogData. FieldValue("myblogID", Nothing) Cpadapter = New OleDbDataAdapter(Cpstring, conn) Dim yy As OleDbCommandBuilder = New OleDbCommandBuilder(Cpadapter) Cpdat = New System.Data.DataSet() Cpadapter.Fill(Cpdat, "myblog") dt = Cpdat.Tables("myblog") dt.Rows(0)("myblog") = myblogreplace.Text dt.Rows(0)("title") = titlereplace.Text Cpadapter.Update(Cpdat, "myblog") conn.Close() panel1.Visible = True Response.Redirect(Request.ServerVariables("SCRIPT_NAME")) End Sub (读者可打开【光盘】|【源文件】|【实例 92 】|【 92.6.txt 】文件,直接复制) ( 14 )定义“ blogdelet_Click ”过程,用于响应【删除】链接按钮的“ OnClick ”事件。 Sub blogdelet_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim conn As OleDbConnection Dim cpConn, Cpstring As String Dim CpCommand As New OleDbCommand cpConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("dat\bad.mdb") conn = New OleDbConnection(cpConn) conn.Open() Cpstring = "delete from myblog where myblogID=" & MyblogData.FieldValue ("myblogID", Nothing) CpCommand = New OleDbCommand(Cpstring, conn) CpCommand.ExecuteNonQuery() conn.Close() panel1.Visible = True Response.Redirect(Request.ServerVariables("SCRIPT_NAME")) End Sub |