Asp.net 如何在单击按钮时找到GridView项?
我正在使用以下代码:Asp.net 如何在单击按钮时找到GridView项?,asp.net,gridview,Asp.net,Gridview,我正在使用以下代码: foreach (GridViewRow dr in gvrejectreq.Rows) { DropDownList ddl=(DropDownList)gvrejectreq.Rows[dr.RowIndex].FindControl("DropDownList1"); string status = ddl.SelectedValue; int userid = gvrejectreq.Rows[dr.RowIndex]. } 如果我理解你的
foreach (GridViewRow dr in gvrejectreq.Rows)
{
DropDownList ddl=(DropDownList)gvrejectreq.Rows[dr.RowIndex].FindControl("DropDownList1");
string status = ddl.SelectedValue;
int userid = gvrejectreq.Rows[dr.RowIndex].
}
如果我理解你的要求…你不需要循环
protected void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e){
if (e.CommandName == "thiscommandname") {
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index];
//and then for example...
string rowText = (LinkButton)selectedRow.Cells[0].Controls[0]).Text;}
}