在Datalist ItemDataBound中获取下拉选择的值

时间:2013-10-28 08:01:46

标签: asp.net datalist

我正在使用datalist中的Dropdown列表。现在,我希望下拉选择值onDatalistItemBound。

如何获得???

1 个答案:

答案 0 :(得分:0)

您的ItemDataBound处理程序应如下所示:

protected void dl_ItemDataBound(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        var myDropDownList = e.Item.FindControl("YourDropDownListID") as DropDownList;
        int currentItemID = int.Parse(this.dl.DataKeys[e.Item.ItemIndex].ToString());

        myDropDownList.DataSource = GetDDLDataSource(currentItemID);
        myDropDownList.DataBind();
    }
}