如何在button_click中找到GridView项?

时间:2009-05-06 10:38:06

标签: 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].
}

1 个答案:

答案 0 :(得分:0)

如果我明白你在问什么......你不需要循环......

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;}
}