C# 从C获取gridview中boundfield的值#
我在asp.net中有一个datagrid,带有一个boundfield。在RowCommand事件中,我想获取这个boundfield的值。columns标记中的boundfield如下所示:C# 从C获取gridview中boundfield的值#,c#,asp.net,C#,Asp.net,我在asp.net中有一个datagrid,带有一个boundfield。在RowCommand事件中,我想获取这个boundfield的值。columns标记中的boundfield如下所示: <asp:BoundField DataField="LoginID" HeaderText="LoginID" InsertVisible="False" ReadOnly="True" SortExpression="LoginID" /> 随之而
<asp:BoundField DataField="LoginID" HeaderText="LoginID" InsertVisible="False"
ReadOnly="True" SortExpression="LoginID" />
随之而来的C#是什么
谢谢在Row_命令事件中,您可以通过以下方式检索单击行的索引:
void GridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
//Check if it's the right CommandName...
if(e.CommandName=="Add")
{
//Get the Row Index
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row
GridViewRow row = ContactsGridView.Rows[index];
// Here you can access the Row Cells
row.Cells[1].Text
}
}
.aspx:
<asp:ImageButton ID="btn_Edit" runat="server" CommandArgument='<%#((GridViewRow)Container).RowIndex%>' CommandName="editResearch" />
假设您指的是GridView而不是DataGrid?
<asp:ImageButton ID="btn_Edit" runat="server" CommandArgument='<%#((GridViewRow)Container).RowIndex%>' CommandName="editResearch" />