![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
protected void GVrentDetails_RowDataBound(object sender, GridViewRowEventArgs e) { ListItem NewItem; string sql; DataTable dt; if (e.Row.RowType == DataControlRowType.DataRow) { DropDownList drop01 = (DropDownList)e.Row.FindControl("ddlRentType"); sql = "select * from dict where fieldMark='rentType'"; dt = commonCls.GetDataTable(sql); drop01.DataSource = dt; drop01.DataTextField = "fieldValue"; drop01.DataValueField = "fieldValue"; drop01.DataBind(); NewItem = new ListItem(); NewItem.Value = "qxz"; NewItem.Text = "请选择"; drop01.Items.Insert(0, NewItem); drop01.SelectedValue = DataBinder.Eval(e.Row.DataItem, "rentType").ToString(); DropDownList drop02 = (DropDownList)e.Row.FindControl("ddlInExpType"); sql = "select * from dict where fieldMark='InExpType'"; dt = commonCls.GetDataTable(sql); drop02.DataSource = dt; drop02.DataTextField = "fieldValue"; drop02.DataValueField = "fieldValue"; drop02.DataBind(); NewItem = new ListItem(); NewItem.Value = "qxz"; NewItem.Text = "请选择"; drop02.Items.Insert(0, NewItem); drop02.SelectedValue = DataBinder.Eval(e.Row.DataItem, "InExpType").ToString(); } }
在RowDataBound事件中绑定下拉框,设置值drop01.SelectedValue = DataBinder.Eval(e.Row.DataItem, "rentType").ToString();