0
我有一個gridview,其中包含我想要觸發事件的每一行上的一個按鈕。點擊按鈕時,事件不會觸發,發生的所有事情是onLoad事件觸發,並且頁面重新加載而不填充gridview。OnRowCommand沒有在GridView上觸發
在.aspx代碼如下:
<asp:GridView id="gvUsers"
OnRowCommand="gvUsers_RowCommand"
AutoGenerateColumns="False"
runat="server">
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID" />
<asp:TemplateField>
<ItemTemplate>
<%# Eval("FirstName")%> <%# Eval("LastName")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="lnkSubmit" runat="server" CommandName="Submit" Text="Action" CommandArgument='<%# CType(Container,GridViewRow).RowIndex %>' ></asp:Button>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
我aspx.cs如下:
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dr As SqlDataReader = db.GetUsers("[email protected]")
Dim users As New List(Of FLLib.FixturesLive.Core.User)
While dr.Read
Dim u As New FLLib.FixturesLive.Core.User
u.UserID = dr("UserID")
u.FirstName = dr("FirstName")
u.LastName = dr("LastNAme")
u.Sex = dr("Sex")
u.EmailAddress = dr("Email")
users.Add(u)
End While
gvUsers.DataSource = users.ToArray
gvUsers.DataBind()
End If
End Sub
Sub gvUsers_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName.Equals("Submit") Then
Dim oItem As GridViewRow = DirectCast(DirectCast(e.CommandSource, LinkButton).NamingContainer, GridViewRow)
Dim RowIndex As Integer = oItem.RowIndex
End If
End Sub
任何幫助,將不勝感激。
感謝 安迪