0

我正在尝试使用 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;
    }
}

谁能帮我解决这个问题???

4

1 回答 1

0

我太晚了,但我现在正在做同样的事情,如果我是对的,那么我认为答案应该是这样的:

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 = ((DataRowView)e.Item.DataItem).Row.ItemArray[index].ToString(); //index is your dropdown index in the datalist
    }
}
于 2018-05-30T13:34:06.990 回答