这是我的标记:-
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="245px" onrowcommand="GridView1_RowCommand" >
<Columns>
<asp:TemplateField>
<ItemStyle BackColor="#CCCCCC" ForeColor="Black" Width="250px" HorizontalAlign="Center"
BorderStyle="None" />
<ItemTemplate>
<asp:LinkButton ID="userList" runat="server" CommandName="Select" CommandArgument ='<%# Container.DataItemIndex %>' Text='<%# Bind("users") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
在代码隐藏中,我试图获取当前行的文本值,但似乎无法获取;
它返回“”。
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowValue = Convert.ToInt32(e.CommandArgument.ToString());
GridView1.SelectedIndex = rowValue;
string test = GridView1.SelectedRow.Cells[0].Text;
}