Checkbox in dataRepeater

  • Thread starter Thread starter simon
  • Start date Start date
S

simon

I have dataRepeater with itemtemlate:
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem,"adv_name") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"adv_start") %></td>
<td><%# DataBinder.Eval(Container.DataItem,"adv_end") %></td>
<td align=center>
<asp:CheckBox Runat=server ID='<%#
DataBinder.Eval(Container.DataItem,"adv_ID") %>'></asp:CheckBox>
</td>
</tr>
</ItemTemplate>


This doesn't work. I can't dynamically set the ID of an ASP.NET CheckBox.
I don't know why, it would be much easier.

But by the book, I can handle the OnItemDataBound event and create the
checkbox dynamically, set the ID property, and insert the
control to the Repeater.

How can I do that? Can I pass the
DataBinder.Eval(Container.DataItem,"adv_ID") to the OnItemDataBound event? I
need this value because it represents the ID property of my checkBox
control.

Any example?

At the end, when user clicks button, I must read the clicked checkboxes.

Thank you,
Simon
 
I'm not 100% sure what you are doing, so I can think of a couple solutions,
but the quickest would be to use a hidden field

<asp:checkbox id="add" runat="server" />
<input type="hidden" id="adv_id" runat="server" value='<%#
DataBinder.Eval(Container.DataItem,"adv_ID") %>' />

you can then see if "add" is checked, and if so get the value from 'adv_id'

Karl
 
Hi,

I know for the hidden field. That is one way.

Do you have solution where you set the id of the checkbox dynamically?
Or any other solution?

Thank you,
Simon
 
Only using OnItemDataBound and creating it dynamically. It's a timing
issue. The controls are created before data is bound...but you need the id
to create the control, so you can't set the id via a bind...

Karl
 
Back
Top