Question

I am using Dropdown list inside datalist. Now, I want dropdown selected value onDatalistItemBound.

How to get it ???

Was it helpful?

Solution

Your ItemDataBound handler should look like :

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();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top