473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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

Feb 14 '07 #1
2 3863
On Feb 15, 12:27 am, bissa...@yahoo.co.uk wrote:
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

--
http://ajaxwidgets.com
Free ASP.NET Ajax Widgets NOW!

Feb 15 '07 #2
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.

Feb 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Scott Lyon | last post by:
I am having a strange problem. The program is a bit complex, but I'll try to simplify what I can. I apologize if this is complicated, but I think this would still be simpler than posting a bunch of...
3
by: John Giblin | last post by:
I have an asp repeater control which I am trying to assign the datasorce to it inline. Here is my code. <asp:Repeater ID="AddOnList" DataSource="<%#...
4
by: Eric | last post by:
Hello, I have the following dataset that I want to bind to a repeater to be displayed as a table. Owner Animal Volume --------------------------- Eric Dog 6 Eric Cat ...
3
by: Kelly Leahy | last post by:
I'm using an Asp:Repeater control with a text box in the item templates. This is for a system that has a number of items that the user can edit and I'd like to generate them based on a list. ...
5
by: George Durzi | last post by:
I currently have an href inside of an asp:repeater <a href='<%# String.Concat("PDFReader.aspx?id=", DataBinder.Eval(Container.DataItem, "ProductUniqueId")) %>' target="_blank">View</a> ...
6
by: simon | last post by:
I have <asp:repeater> with Item template: <ItemTemplate> <%# writeLine(DataBinder.Eval(Container.DataItem, "danIme"),DataBinder.Eval(Container.DataItem, "timeStart"))%> </ItemTemplate> In my...
1
by: Fred Dag | last post by:
As far as I can work out when using the OnTextChanged event I cannot get the TextBox and Labels values when the event fires as they are populated by a <asp:repeater and so don't have values. If...
0
by: deathtospam | last post by:
A few weeks ago, I created a Classic ASP page that connects to a machine with SQL Server installed on it, prompts the user to select a database on that server, then lists all of user-created stored...
3
by: Homer J. Simpson | last post by:
I have the following stored procedure: ALTER PROCEDURE . AS BEGIN SET NOCOUNT ON; SELECT COUNT(*) FROM QUICKNOTES END ....and the following data source in my .aspx file:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.