DataRepeater FindControl("controlX") ControlX was added to placeho

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a repeater control with a placeholder inside ItemTemplate.
myRpt_ItemDataBound() event adds dropdown conrol (drpCntlr.ID = ControlX) to
a place holder.
Then on postback, I want to read this value selected by a user:

drpX = (DropDownList)rptSelect.Items.FindControl("ControlX");

but drpX is null.
How can I get the value of a control which was added dynamically to a
placeholder?

Thank you
 
Hi,

you'd need to add it in ItemCreated so that control instance exists also on
postback. In ItemdataBound you'd just deal with the data-binding specific
stuff, not control creation (if you need to check from data which type of
control to create, you can do that in ItemCreated when e.Item.DataItem is
not null, that is true when ItemCreated runs just before ItemdataBound e.g
on DataBind() call)
 
Back
Top