关于下拉列表的求救
for (int i = 0; i < NavigateTree.InfinityTree.Rows.Count; i++)
{
ClassDrop.Items.Add(NavigateTree.InfinityTree.Rows[i]["StrTree"].ToString());
ClassDrop.Items[i].Value = NavigateTree.InfinityTree.Rows[i]["Classid"].ToString();
}
ClassDrop.Items.Insert(0, "一级分类");
ClassDrop.Items[0].Value = "0";
Connection = new OleDbConnection(DataProvider.ConnectionString);
Command = new OleDbCommand();
Command.Connection = Connection;
Command.CommandText = "Select * From aClass where Classid=" + ClassDrop.SelectedValue;
Connection.Open();
dr= Command.ExecuteReader();
为什么ClassDrop.SelectedValue选出来的为空??
------解决方案--------------------for (int i = 0; i < NavigateTree.InfinityTree.Rows.Count; i++)
{
ClassDrop.Items.Add(NavigateTree.InfinityTree.Rows[i]["StrTree"].ToString());
ClassDrop.Items[i].Value = NavigateTree.InfinityTree.Rows[i]["Classid"].ToString();
}
ClassDrop.Items.Insert(0, "一级分类");
ClassDrop.Items[0].Value = "0";
===========================================
只往里添加了。也没有选择阿
另外,添加的时候value和text为什么要分开呢
ListItem itm=new ListItem(value,text);
ClassDrop.Items.Add(itm);