Ok, how would you go about binding a control to the Repeater that,
In that case, you bind it in the OnItemDataBound event of the Repeater.
Could you provide code (or another resource) that shows how to do this?
Because I've tried using that event but the drop down just isn't getting
filled.
When I'm use FindControl() to get the reference to the control, it always
returns null. Here's my code:
private void Repeater1_ItemDataBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
UserDetailsList userDetailsList = UserDetails.FindAll();
DropDownList ddl = (DropDownList)e.Item.FindControl("DropDownList2");
if(ddl != null)
{
ddl.DataSource = userDetailsList;
ddl.DataTextField = "Name";
ddl.DataValueField = "UserId";
ddl.DataBind();
}
}
'userDetailsList' is just an ArrayList. Since the variable 'ddl' is always
null, it never populates. I must be doing *something* wrong...
The catch here is that you need to refill the dropdownlist on
postback, otherwise its selection would be lost.
Alright.
This means that, even on postback, you need to databind
the repeater (and automatically, the dropdownlist). So do
NOT use the If(Not IsPostback) condition.
Then how do I determine if the form needs processing because
the user 'Submit'ted the form?
After databinding, in the case of postback, you can read
the selected value in the dropdownlist.
It's insane that using a DropDownList in a Repeater control
requires the developer to jump through so many hoops...
thnx,
Christoph