ASP .NET Beginner trying to figure out <asp:Repeater and checkboxes

B

bissatch

Hi,

I am trying to output a list of checkboxes. Using ASP .NET controls, I
was able to create the following:

<label for="colour_red">Red: </label><asp:CheckBox ID="colour_red"
runat="server" /><br />
<label...
<label...
<label...

I figured because they all follow the same HTML structure there would
be a way of outputing a list of these using the Repeater control. For
example:

<asp:Repeater id="colours" runat="server">

<ItemTemplate>
<label for="...">...</label><input type="checkbox" name="..."
value="..." /><br/>
</ItemTemplate>

</asp:Repeater>

An XML file was used to store the data (key, name, label text) and I
was able to fill in the missing parts '...' from this. This seemed to
work fine BUT because I had now changed the checkbox tag from
<asp:CheckBox... to <input type="checkbox"... it didnt take advantage
of the ViewState feature and my selections were not saved when the
form was submitted and the page reloaded.

I have also tried using <asp:CheckBoxList... but dont like the way
that the server creates the HTML for me. I think in this case it even
used a table for layout which is a Neddy-no-no in my book.

Whats the best way to go about this? Thanks

Burnsy
 
T

Thomas Hansen

Hi,

I am trying to output a list of checkboxes. Using ASP .NET controls, I
was able to create the following:

<label for="colour_red">Red: </label><asp:CheckBox ID="colour_red"
runat="server" /><br />
<label...
<label...
<label...

I figured because they all follow the same HTML structure there would
be a way of outputing a list of these using the Repeater control. For
example:

<asp:Repeater id="colours" runat="server">

<ItemTemplate>
<label for="...">...</label><input type="checkbox" name="..."
value="..." /><br/>
</ItemTemplate>

</asp:Repeater>

An XML file was used to store the data (key, name, label text) and I
was able to fill in the missing parts '...' from this. This seemed to
work fine BUT because I had now changed the checkbox tag from
<asp:CheckBox... to <input type="checkbox"... it didnt take advantage

Why did you change from ASP.CheckBox to HTML input field...??

Don't do it!

If you want to see a nice example of using a Repeater, check ot this:
http://ajaxwidgets.com/AllControlsSamples/Repeater.aspx

(Click the "View code" button at the top left part of the page)

This is created using an Ajax Framework, but it'll be no different
with "conventional" asp.net...
If you want to have CheckBoxes then exchange the "Button" part in the
ASPX with "CheckBox" (but KEEP the "asp:" part...)

..t
 
B

bissatch

Why did you change from ASP.CheckBox to HTML input field...??
Don't do it!

I did try:

<asp:Repeater id="colours" runat="server">

<ItemTemplate>
<label for="...">...</label><asp:CheckBox ID="..." value="..."
runat="server" /><br/>
</ItemTemplate>

</asp:Repeater>

....it doesnt work and the <asp:CheckBox 's are not converted into
their HTML counterpart.
If you want to see a nice example of using a Repeater, check ot this:http://ajaxwidgets.com/AllControlsSamples/Repeater.aspx

The View Code didnt give me the aspx source code and it seems a bit
much surely for what i want to do. All i want is the method for using
the repeater control to reduce the number of times im writing code
that, although the label and value may change, the HTML structure will
be the same each time. I also want to maintain the ViewState which my
working example doesnt do. Im sure your example does wonders but I
just want to learn the basics for now. Please bear in mind I am
starting this for the first time and dont know exactly how it all
works.
 

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,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top