protected void gridView_RowEditing(object sender, GridViewEditEventArgs e)
{
System.Data.DataRowView drv = (System.Data.DataRowView)gridView.Rows[e.NewEditIndex].DataItem;
//索引编辑时
this.gridView.EditIndex = e.NewEditIndex;
this.BindData();
//绑定编辑状态的Dropdownlist数据
DropDownList ddlUserName = (DropDownList)gridView.Rows[gridView.EditIndex].FindControl("ddlUserName");
ddlUserName.DataSource = new BLL.UserBLL().GetList(" UsRo_fk_Ro_ID = 5");
ddlUserName.DataBind();
DropDownList ddlDwName = (DropDownList)gridView.Rows[gridView.EditIndex].FindControl("ddlDwName");
ddlDwName.DataSource = new BLL.DanweiBLL().GetAllList(" Dw_parentID = Dw_ID");
ddlDwName.DataBind();
HiddenField hdfUserName = (HiddenField)gridView.Rows[gridView.EditIndex].FindControl("hdfUserName");
HiddenField hdfDwName = (HiddenFie
gridview行编辑时绑定Dropdownlist并选中对应值
最新推荐文章于 2014-10-23 15:07:17 发布
这段代码展示了如何在GridView的行编辑模式下,为Dropdownlist控件绑定数据,并根据隐藏字段的值选中对应的Dropdownlist项。通过DataRowView获取当前编辑行的数据,然后使用BLL层方法获取Dropdownlist的数据源,进行数据绑定。接着,找到编辑行中的Dropdownlist和HiddenField控件,根据HiddenField的值设置Dropdownlist的选中项。
摘要由CSDN通过智能技术生成