简单问题,在线等。
我把访问的数据绑定到datalist下,在使用datalist事件出错,请指教。
源码:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="test8.aspx.vb" Inherits="WebApplication1.test8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>test8</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:DataList id="dlstTitles" OnItemCommand="DataList_ItemCommand" OnEditCommand="DataList_EditCommand" OnDeleteCommand="DataList_DeleteCommand" OnUpdateCommand="DataList_UpdateCommand" GridLines=Both runat="server">
<ItemTemplate>
<%# container.dataitem("Title")%>
<br>
<asp:LinkButton runat="server" text="Edit" CommandName="edit"></asp:LinkButton>
<asp:LinkButton runat="server" text="Delete" CommandName="delete"></asp:LinkButton>
<asp:LinkButton runat="server" text="Update" CommandName="update"></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
<asp:Label id="lbMessage" style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 240px"
runat="server" Width="104px" Height="48px">Label</asp:Label></FONT>
</form>
</body>
</HTML>
-----------------------
Imports System.Data.SqlClient
Public Class test8
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents dlstTitles As System.Web.UI.WebControls.DataList
Protected WithEvents lbMessage As System.Web.UI.WebControls.Label
Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton
Protected WithEvents LinkButton2 As System.Web.UI.WebControls.LinkButton
Protected WithEvents LinkButton3 As System.Web.UI.WebControls.LinkButton
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
Dim con As SqlConnection
Dim com As SqlCommand
Dim dtr As SqlDataReader
con = New SqlConnection("server=samsung;user id=sa;password=;database=pubs;connection reset=false")
con.Open()
com = New SqlCommand("select Title from titles", con)
dtr = com.ExecuteReader()
dlstTitles.DataSource = dtr
dtr.Close()
con.Close()
End If
End Sub
Sub dlstTitles_ItemCommand(ByVal s As Object, ByVal e As DataListCommandEventArgs)
lbMessage.Text = "<li>Item Command"
End Sub
Sub dlstTitles_EditCommand(ByVal s As Object, ByVal e As DataListCommandEventArgs)
lbMessage.Text = "<li>Editing Item"
End Sub
Sub dlstTitles_DeleteCommand(ByVal s As Object, ByVal e As DataListCommandEventArgs)
lbMessage.Text = "<li>Deleting Item"
End Sub
Sub dlstTitles_UpdateCommand(ByVal s As Object, ByVal e As DataListCommandEventArgs)
lbMessage.Text = "<li>Updating Item"
End Sub
End Class
-------------------------------
出错提示:
Compiler Error Message: BC30456: 'DataList_EditCommand' is not a member of 'ASP.test8_aspx'.