我写了2个dropdownlist,在选取第一个dropdownlist1的值(从数据库中加载)后我要在dropdownlist2中动态添加从数据库中选取的和dropdownlist的值对应的另一个字段的值,给如何获取啊?我试写了代码,可是不能得到,以下是我写的,请指点:
SqlConnection sqlstr1 = new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlDataAdapter myda1 = new SqlDataAdapter("select Student_Name from Student_Info where Student_Id='"+ this.DropDownList1.SelectedItem.Text.Trim().ToString() +"'",sqlstr1);
DataSet ds1 = new DataSet();
myda1.Fill(ds1);
string s=?;
this.DropDownList2.Items.Add(new ListItem(?));
怎么样处理‘?’处啊?
解决方案 »
- 有空的,帮我解决个问题。。
- |zyciis| 如何让用户点出Button的时候,后台在Pageload中停止代码执行,不让他走Button_Click事件呢 谢谢
- net 如何 建立http 连接,发送byte[]数据?类似于 java。net。url?
- DataList不能更新
- 另一个网页跳转到另一个网页框架页面的问题
- 请问 脚本如何取得 <asp:Image ID="Image1" runat="server" ImageUrl="~/image/male.gif" /> 的ImageUrl完整路径
- 调用引用类型参数dll错误
- 怎么在后台向页面写html代码,并且控制在页面显示的位置.
- 有谁知道吗?????求教!!
- session问题
- 从未用过iframe,谁给我一个ifame的完整示例(asp.net/c#)
- 程序完成后外部访问问题~~~~~~~~~~~~~~~~!Help
this.Dropdownlist.Databind();
1.dropdownlist1的autopostback属性有没设置为true.
2.dropdownlist1的selectedindexchanged事件中有没有加载dropdownlist2
dropdownlist2.DataValueField
和dropdownlist2.DatatextField
最后dropdownlist2.databind
并且设置事件SelectedIndexChanged
在后台事件里,取出该下拉框值
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string myKeyid = this.DropDownList1.SelectedValue;
string sql = "select 字段1,字段2 from 表 where id = '" + myKeyid + "' ";
//通过SQL语句取得数据集
this.DropDownList2.DataSource = 数据集;
this.DropDownList2.DataValueField = 字段1名称;
this.DropDownList2.DataTextField = 字段2名称;
this.DropDownList2.DataBind();}
取得数据集的过程要自己写,不要忘记了
this.DropDownList2.DataValueField = 字段1名称;
this.DropDownList2.DataTextField = 字段2名称;
这两句话我不是很明白,为什么都是dropdownlist2的属性,取得的字段名为什么不一样?到底是怎样的?
第二个表示将显示出来的值绑定到哪个字段
要注意是文本,要用双绰号括起来.