I have a datagrid in asp.net, with a boundfield. On the RowCommand event, I want to get the value of this boundfield. The boundfield, in the columns tag, loooks as below:
<asp:BoundField DataField="LoginID" Head开发者_开发问答erText="LoginID" InsertVisible="False"
ReadOnly="True" SortExpression="LoginID" />
What would the accompanying C# be?
Thanks
In the Row_Command Event you can retrieve the index of the clicked Row in this way :
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
}
}
protected void gv_research_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
int index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "editResearch")
{
txt_researchName.Text = gv_research.Rows[index].Cells[1].Text.TrimEnd();
}
}
catch (Exception ee)
{
string message = ee.Message;
}
}
.aspx:
<asp:ImageButton ID="btn_Edit" runat="server" CommandArgument='<%#((GridViewRow)Container).RowIndex%>' CommandName="editResearch" />
精彩评论