Checkbox in dataRepeater

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
 
K

Karl Seguin

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
 
S

simon

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
 
K

Karl Seguin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top