GridView添加了一列DropDownList1,我在GridView中加一个保存的按钮,点击按钮的时候,怎么取得当前行DropDownList1列的值呢?

解决方案 »

  1.   

    button和dropdown是存在于同一行的话:
    //button _click事件中:
      GridViewRow row = (sender as Button).Parent.Parent as GridViewRow;
               DropDownList ddl=row.FindControl("DropDownList1") as DropDownList;
                }
      

  2.   

    可我希望在GridView1_RowCommand(object sender, GridViewCommandEventArgs e)方法里处理因为还要根据e.CommandArgument.ToString();获得当前记录对应的ID,才能更新当前记录啊
      

  3.   

    这个..可以有...    int index = Convert.ToInt32(e.CommandArgument);     GridViewRow row = GridView1.Rows[index]; DropDownList ddl=row.FindControl("DropDownList1") as DropDownList;
      

  4.   

    e.CommandArgument默认是不是行索引呢?》
      

  5.   

    一般前台页面中用 CommandArgument='<%# Eval("id") %>'绑定当前记录的ID号,然后在后台用e.commandargument取到当前记录的ID号吧,那么大师说的这种用法似乎e.CommandArgument就是行索引了吧,
    (不过大师前一种方法在GridView1_RowCommand方法中貌似也能用 )
      

  6.   

    此方法在GridView1_RowCommand()方法中,系统提示sender为gridview对象
      

  7.   

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
      {
      int index = Convert.ToInt32(e.CommandArgument);
      GridViewRow selectRow = GridView1.Rows[index];
    }
    或Control   cmdControl   =   e.CommandSource   as   Control;   
      row   =   cmdControl.NamingContainer   as   GridViewRow; 
      string   str   =   row.Cell[0].Text;