protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            DropDownList drl = e.Row.FindControl("DropDownList1") as DropDownList;
            if (drl != null)
            {
                DataRowView dr = e.Row.DataItem as DataRowView;
                string LabelID = dr["LabelID"].ToString();
                DataTable dt = SqlSelect.getTable();
                drl.DataSource = dt;
                drl.DataTextField = "LableId";
                drl.DataValueField = "LableId";
                drl.DataBind();
            }
        }        public void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int i = e.RowIndex;
            DropDownList dls = (GridView1.Rows[e.RowIndex].FindControl("DropDownList1") as DropDownList);
            string newLabel = dls.SelectedValue;
        }RowUpdating时newlabel总是dropdownlist的第一个值,也就是说dropdownlist总是只选默认的第一个选项,要怎样才能让newlabel取得选中值

解决方案 »

  1.   

    (GridView1.Rows[e.RowIndex].FindControl("DropDownList1") as DropDownList); 
    估计问题在这,e.RowIndex改成GridView1.EditIndex
      

  2.   

    试了不行,
    问题在于事件顺序,
    编辑按钮->RowEditing->RowDataBound
    更新按钮->RowDataBound->RowUpdating
    每次RowDataBound时绑定下拉框,绑定后都默认选择第一项
    就是不知有什么解决办法
      

  3.   

    你看下Update时焦点有没离开DropDownList
      

  4.   

    dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[1].Value.ToString();
    取得相应行和列的值
      

  5.   

    自己解决
    改成RowCommand里更新就可以了。
      

  6.   

    我也遇到这问题- -!你怎么解决的。。把代码放到RowCommand事件里就行?