0

我有这个代码,我无法根据用户单击的行获取学生编号的值

ASPX

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" 
            OnSelectedIndexChanged="SelectEvent_click"  HorizontalAlign="Center" DataKeyNames="StudentNumber">
            <Columns>
            <asp:BoundField DataField="StudentNumber" HeaderText="Student Number"/>
            <asp:BoundField DataField="F_name" HeaderText="First name"/>
            <asp:BoundField DataField="L_name" HeaderText="Last name"/>
            <asp:BoundField DataField="Course" HeaderText="Course"/>
            <asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:dd-MMM-yyyy}"/>
            <asp:TemplateField HeaderText="View Application">
                <ItemTemplate>
                    <asp:LinkButton ID="lnkApplication" runat="server" onClick = "SelectEvent_click"
                        Text="Select"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            </Columns>
        </asp:GridView>

VB

 Protected Sub SelectEvent_click(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged
        Label1.Text = GridView1.SelectedValue
        If GridView1.SelectedIndex >= 0 Then
            Response.Write(Label1.Text)
            Session("StudentNumber") = Label1.Text
            Response.Redirect("PCOApplicationView.aspx")
        Else
            Response.Write("Something bad happen please try again later!!")
        End If
    End Sub
4

1 回答 1

0

您可以在按钮单击事件上使用 NamingContainer 属性,如下所示:

Dim btn As LinkButton = DirectCast(sender, LinkButton)
GridViewRow = DirectCast(btn.NamingContainer, GridViewRow)
于 2013-10-05T14:42:18.720 回答