我有一个 gridView 。在后面的代码中,我想获取 Id 和 Name
<asp:GridView ID="GridViewCategory" runat="server"
OnSelectedIndexChanged="GridViewCategory_SelectedIndexChanged"
OnPageIndexChanging="GridViewCategory_PageIndexChanging"
AllowPaging="True" DataKeyNames="Id"
CellPadding="4" ForeColor="#333333" GridLines="None"
>
<Columns>
<asp:BoundField DataField="Id" HeaderText="Идент. номер" ItemStyle-Wrap="false" ItemStyle-Width="20%" />
<asp:BoundField DataField="Name" HeaderText="ALl name For" ItemStyle-Wrap="false" ItemStyle-Width="60%" />
<asp:CommandField SelectText="Избери" ShowSelectButton="True" />
</Columns>
我通过这个得到 ID:
protected void GridViewCategory_SelectedIndexChanged(object sender, EventArgs e)
{
int abv = Convert.ToInt32(GridViewCategory.SelectedValue);
//Label labelName = (Label)GridViewCategory.SelectedRow.FindControl("Name"); this is not working I think because it is BoundField And rows don't have Id only DataField
}
但是如何获得这个 ID 的名字