DataList中嵌套了DropDownList。此时需要实现选择DDL中的值,在DataList外有个Label

DataList中嵌套了DropDownList。此时需要实现选择DDL中的值,在DataList外有个Label吧。把DDL的值输出到Label中,如果DDL选择别的值,那么就清除之前的输出,输出新选择的值。当然,DataList中肯定是有多行DropDownList的,一行也可能会有几个DropDownList。。怎么实现?http://maq.tw/order 这个页面。急!!!

第1个回答  2011-03-23
把DDL的AutoPostBack属性设置为 True,把DDL的EnableViewState设置为True, 然后在 DDL的TestChang时间里写代码,让Lable的text值等于DDL的选中值 例如
protected void DDL_TextChanged(object sender, EventArgs e)
{
Lable1.Text = DDL.SelectedItem.Text;
}
//protected void DDL_SelectedIndexChanged(object sender, EventArgs e)
// {
// Lable1.Text = DDL.SelectedItem.Text;
// }
以上两种方法均可实现!

参考资料:

第2个回答  2011-03-23
我看了下那个网站,这样可以实现。

遍历DataList中的DropDownList。把每项输出到Label。
比如
for (int i = 0; i < DataList.Items.Count; i++)
{
DropDownList ddl= DataList.Items[i].FindControl("ddl") as DropDownList;
Label1.Text = ddl.SelectedValue + "<br>"; //添加一条数据就换行
}

这样有个缺点,就是没有选择过的DDL也会输出值。
第3个回答  2011-03-23
下拉框有一个选择的值,还有一个显示的值;在下拉框的变化后事件中用选中的值作参数在基础数据表里查询相关记录显示出来就可以了。追问

可以说的明白点吗,我有点迷糊,呵呵。

第4个回答  2011-03-23
dropdownlist控件里面有个selectedindexchanged事件,用这个就可以实现了,然后具体是选中了哪个下拉框,你可以用findcontrol方法来解决
第5个回答  2011-03-23
DropDownList 在外面定义好selectvaluechange的方法。然后在方法里写代码
然后在把DropDownList 放到DataList里嵌套就OK了

{
DropDownList ddl =sender as DropDownList ;
Lable1.Text=ddl.SelectValue;
}
相似回答