标签:res selected state 方法 display ted tar code bind
1、直接赋值
foreach (DataRow dr in ds.Tables[0].Rows) //遍历获取两个值 { Ext.Net.ListItem listItem = new Ext.Net.ListItem(); //每次创建一个Ext.Net.ListItem的对象 listItem.Value = dr["ID"].ToString(); listItem.Text = dr["Name"].ToString(); drpComBox.Items.Add(listItem); }
2、设置选中项,注意这种方法不能用于Store方式
public void SetListValue(ComboBox p_rg, string p_value) { int num = 0; foreach (ListItem listItem in (StateManagedCollection<ListItem>)p_rg.Items) { if (listItem.Value == p_value) { p_rg.SelectedIndex = num; ExtNet.AddScript(string.Format("{0}.setValue(\"{1}\");", (object)p_rg.ClientID.ToString(), (object)p_value)); break; } ++num; } }
3、使用Store方式
this.drpComBox.DisplayField = "Name"; this.drpComBox.ValueField = "ID"; this.drpComBOx.StoreID = "storeStudent";
protected void storeStudent_Refresh(object sender, StoreRefreshDataEventArgs e) { .. storeStudent.DataSource = ds.Tables[0]; storeStudent.DataBind(); }
设置当前值
this.drpComBox.SetValue(fenZuId); this.drpComBox.Text = v.LeiXingMingCheng;
标签:res selected state 方法 display ted tar code bind
原文地址:https://www.cnblogs.com/zhaogaojian/p/9215286.html