المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Accessing a dynamically created drop down list



C# Programming
11-19-2011, 07:51 AM
I have the following method in a class library that creates a dropdown menu populated using linq to sql.

public DropDownList GetCategoryList() { ArticleDataDataContext dc = new ArticleDataDataContext(); DataBuddy db = new DataBuddy(dc.getAllCategories()); List result = db.EnumerateISingleResultAsString(); DropDownList d = new DropDownList(); d.ID = "ddCatList"; d.ViewStateMode = ViewStateMode.Enabled; foreach (string item in result) { d.Items.Add(new ListItem(item, item, true)); } return d; }
This works fine but I cannot figure out how to access the control on postback.

I have tried the following in a button click event handler but it doesn't work.

DropDownList dd = (DropDownList)this.FindControl("ddCatList");