gridview中Combox如何定默值
在gridview中有combox控件,但combox中的值根前行的值哪一。
- C# code
protected void gv_EmpInfor_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.RowState == DataControlRowState.Alternate || e.Row.RowState == DataControlRowState.Normal) { GridViewRow drv = e.Row; //首部的代 string sparentcode = ((System.Data.DataRowView)(drv.DataItem)).Row.ItemArray[9].ToString(); //首部的 string sPartDeptcode = ((System.Data.DataRowView)(drv.DataItem)).Row.ItemArray[10].ToString(); //位表中的位 string stechcode = ((System.Data.DataRowView)(drv.DataItem)).Row.ItemArray[8].ToString(); //工表中的架位代 string sEmpTechcode = ((System.Data.DataRowView)(drv.DataItem)).Row.ItemArray[6].ToString(); //如果工表中架位代空自定初始部,子部,位并生成。 //首部控件 Control control = e.Row.FindControl("rcb_ParentDept"); if (control != null) { DropDownList rcb_firstdept = control as DropDownList; rcb_firstdept.DataSource = GetParentDept(); rcb_firstdept.DataTextField = "departmentname"; rcb_firstdept.DataValueField = "PartDeptCode"; rcb_firstdept.DataBind(); rcb_firstdept.Items.Insert(0, new ListItem("", "-1")); // rcb_firstdept.SelectedItem.Text = "集"; rcb_firstdept.Attributes.Add("RowIndex", e.Row.RowIndex.ToString()); if (sEmpTechcode == string.Empty) {//此是-----我置了值可示的值是“” rcb_firstdept.SelectedItem.Value = "00002$FA";// sparentcode + "$" + sPartDeptcode; // rcb_firstdept.SelectedIndex = rcb_firstdept.Items.IndexOf(new ListItem("生部")); } } //子部控件 Control control1 = e.Row.FindControl("rcb_SubDept"); if (control != null) { DropDownList rcb_subDept = control1 as DropDownList; rcb_subDept.Attributes.Add("RowIndex", e.Row.RowIndex.ToString()); } //位列表控件 Control control2 = e.Row.FindControl("rcb_Technical"); if (control != null) { DropDownList rcb_tchnical = control2 as DropDownList; rcb_tchnical.Attributes.Add("RowIndex", e.Row.RowIndex.ToString()); } } } }//此是-----我置了值可示的值是“”
[解决办法]
你把默认值 外面加一个判断,如果已有选择就不让它走你的默认值了! 否则,程序每走到这,都会给那个下拉值赋成 “请选择”