如何在选定索引更改时查找下拉列表选择值 [英] How to find drop down List select value at selected index change
本文介绍了如何在选定索引更改时查找下拉列表选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个数据列表.里面有两个下拉列表.在第一个下拉列表的选定索引上,我想绑定第二个下拉列表.为此,我需要选择第一个下拉列表的选定值.如何实现,因为我没有得到第一个下拉列表的选定值.
选定索引处的代码
Hello all,
I have a datalist.Inside it has two dropdowns. On the selected index of first dropdown I want to bind the second drop down.for that i have to need the selected value of first drop down.How it will be done bcz i am not getting the selected value of first drop down.
code at selected index
DropDownList ddlcountry= (DropDownList)DataList1.FindControl("ddlcountry");
int id=convert.toint32(ddlcountry.selectedvalue);
但在ddlcountry
处显示null
.
谢谢&问候,
amit
but it shows null
at ddlcountry
.
Thanks & Regards,
amit
推荐答案
您没有在DataList本身上找到控件.您可以在DataList的每个DataListItem上执行此操作.请参考下面的代码:
You dont find the control on the DataList itself. You do it on every DataListItem of the DataList. Refer to the code below:
(DropDownList)DataList1.Items[0].FindControl("ddlcountry");
FindControl
需要知道它正在查找哪个项目,因为
DataLis
t包含模板中每个控件的许多副本.您需要对DataLis
t中的所有项目进行迭代以找到下拉菜单并对其进行操作,您可以使用下面的代码,
FindControl
needs to know which Item it is looking in because a
DataLis
t contains many copies of each control that is in a template.You need to iterate all items inDataLis
t to find the dropdown and manipulate them, you can use the code below,
foreach(DataListItem dlistItem in DataList1.Items)
{
DropDownList ddlcountry= dlistItem.item[i].
findControl("ddlcountry") as DropDownList;
if(ddlcountry!=null)
{
int id=Convert.ToInt32(ddlcountry.SelectedValue);
}
}
希望这会有所帮助.
Hope this will help.
这篇关于如何在选定索引更改时查找下拉列表选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文