/// <summary> /// 绑定数据 /// </summary> public void DataBind() { try { if (IsDShowName) { airSpan.Visible = true; } else { airSpan.Visible = false; } if (this.DataSource == null && this.DataTableSource == null) { Bd_Air_Carrier[] allAir = Manage.GetArray(""); ddl_AirCode.Items.Clear(); if (IsShowAll) { ddl_AirCode.Items.Add(new ListItem(this.DefaultOptionText, this.DefaultOptionValue)); txt_AirCo.Text = this.DefaultOptionValue; } foreach (Bd_Air_Carrier item in allAir) { ListItem items = new ListItem(); items.Text = item.Code + "-" + item.ShortName; items.Value = item.Code; ddl_AirCode.Items.Add(items); } //最大输入字符数 txt_AirCo.MaxLength = this.InputMaxLength; //设置下拉列表宽度 ddl_AirCode.Width = this.ddlWidth; //文本框宽度 txt_AirCo.Width = this.TxtWidth; } else { ddl_AirCode.Items.Clear(); Type t = null; string[] strArr = null; List <string> TextList = null; List <string> ValList = null; if (this.DataSource != null) { foreach (Object item in this.DataSource) { t = item.GetType(); if (t.IsClass) { //绑定Class类型的List strArr = this.DataFiledText.Split(new string[] { this.SplitChar }, StringSplitOptions.None); TextList = new List <string>(); foreach (string strPName in strArr) { TextList.Add(t.GetProperty(strPName).GetValue(item, null).ToString()); } strArr = this.DataFiledValue.Split(new string[] { this.SplitChar }, StringSplitOptions.None); ValList = new List <string>(); foreach (string strPName in strArr) { ValList.Add(t.GetProperty(strPName).GetValue(item, null).ToString()); } ListItem items = new ListItem(); items.Text = string.Join(this.SplitChar, TextList.ToArray()); items.Value = string.Join(this.SplitChar, ValList.ToArray()); ddl_AirCode.Items.Add(items); } else { break; } } } else { //数据源为DataTable if (this.DataTableSource != null) { foreach (DataRow dr in this.DataTableSource.Rows) { //显示列数据 strArr = this.DataFiledText.Split(new string[] { this.SplitChar }, StringSplitOptions.None); TextList = new List <string>(); foreach (string strPName in strArr) { TextList.Add(dr[strPName] != DBNull.Value ? dr[strPName].ToString() : ""); } //绑定值数据 strArr = this.DataFiledValue.Split(new string[] { this.SplitChar }, StringSplitOptions.None); ValList = new List <string>(); foreach (string strPName in strArr) { ValList.Add(dr[strPName] != DBNull.Value ? dr[strPName].ToString() : ""); } ListItem items = new ListItem(); items.Text = string.Join(this.SplitChar, TextList.ToArray()); items.Value = string.Join(this.SplitChar, ValList.ToArray()); ddl_AirCode.Items.Add(items); } } } //绑定值类型的List if (t != null && t.IsValueType) { ddl_AirCode.DataSource = this.DataSource; ddl_AirCode.DataBind(); } if (IsShowAll) { ddl_AirCode.Items.Insert(0, new ListItem(this.DefaultOptionText, this.DefaultOptionValue)); txt_AirCo.Text = this.DefaultOptionValue; } //最大输入字符数 txt_AirCo.MaxLength = this.InputMaxLength; //设置下拉列表宽度 ddl_AirCode.Width = this.ddlWidth; //文本框宽度 txt_AirCo.Width = this.TxtWidth; t = null; strArr = null; TextList = null; ValList = null; } scriptLiter.Text = CreateScript(); } catch { ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), "alert('航空公司控件加载错误!');", true); } }