使用Datalist ItemDataBound获取下拉选择的值

时间:2013-10-28 09:37:18

标签: asp.net datalist

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

任何人都可以帮我这个???

1 个答案:

答案 0 :(得分: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
    }
}