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取得选中值
{
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取得选中值
估计问题在这,e.RowIndex改成GridView1.EditIndex
问题在于事件顺序,
编辑按钮->RowEditing->RowDataBound
更新按钮->RowDataBound->RowUpdating
每次RowDataBound时绑定下拉框,绑定后都默认选择第一项
就是不知有什么解决办法
取得相应行和列的值
改成RowCommand里更新就可以了。