【发布时间】:2018-05-30 21:34:06
【问题描述】:
我正在尝试使用 Datalist OnItemDataBound 获取 Dropdownlist 选定值。
DlSubjects 是主 DataList,dlTests 是嵌套 DataList。下拉列表包含在 dlSubjects 中。
我的代码:
protected void dlSubjects_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataList dlTests = e.Item.FindControl("dlTests") as DataList;
DropDownList drpTopic = e.Item.FindControl("drpTopic") as DropDownList;
string Value = drpTopic.SelectedValue;
}
}
谁能帮我解决这个问题???
【问题讨论】:
-
那么问题或异常是什么?
dlTests是嵌套在DataList中的dlSubjects吗? -
是的,所以根据下拉选择的值,我将过滤 dlTests。
-
我没有得到任何异常,但它没有给我选择的价值。它给出了下拉列表的默认选定值。
-
下拉列表包含在主 DataList 的 dlSubjects 中。
-
那么你也在回发数据绑定数据列表。在
!IsPostBack检查中将 page_load 中的数据绑定内容包装起来。