WebCombo取组合框当前显示的文本


 1取组合框当前显示的文本,3种写法
 2combNdGys.SelectedCell.ToString();  当为编辑状态时,如果不是选,而是输入时,则出错,而comboPJNo.DisplayValue.ToString();则不出错
 3ComboHtType.SelectedCell.Text;
 4comboPJNo.DisplayValue.ToString();
 5this.ComboHtType.SelectedRow.Cells[0].ToString() //所选行的第一列文本
 6注:如果WebCombo不输入或留空时则出错
 7
 8解决方法:动态的编写语句(否则其会清空数据源,造成WebCombo不输入或留空时出错)
 9    protected void Page_Load(object sender, EventArgs e) //动态的编写语句
10    {
11        if (!IsPostBack)
12        {
13            this.WebCombo2.DataSource = BuildStateList();
14            this.WebCombo2.DataBind();
15            this.WebCombo1.Columns.Clear();
16            
17            this.WebCombo1.DataSource = pzcDbHelperSQL.pzcGetDataTable("select * from T_Custom"); //动态装入
18            this.WebCombo1.DataBind();
19            this.WebCombo1.Columns[0].Header.Caption = "pzc";
20        }

21    }

22    protected void Button2_Click(object sender, EventArgs e)
23    {
24        if (this.WebCombo1.DisplayValue == null)
25        {
26            Response.Write("null");
27        }

28        else { Response.Write(this.WebCombo1.DisplayValue.ToString()); }
29       
30    }

31

你可能感兴趣的:(null)