469,889 Members | 1,274 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

Huge number of checkboxes to be populated from database

I have a database with 90-odd true-false values that I need to display
on a webform as checkboxes. There are also some other values (numbers
and text) that need to be displayed.

I'm wondering the best way to do this! Do I need to individually
place and databind 90 checkboxes (and label them!) or is there a
better way? Note, this is 90 values *per row* of the
query...ultimately I'd like to be able to page through this data.

Thanks for any help.

Lerch

Nov 17 '05 #1
3 1684
A solution could be a PlaceHolder control.

Suppose that you have the result of your query in a DataReader. You
loop through each field of a row, then you add dynamic checkboxes in
the PlaceHolder. That way you can set the label and the checked value
easily within your query.

Everything is dynamic so you don't have to modify your webform, you
just modify your query instead. Hope this helps!

Matt
On Fri, 01 Aug 2003 18:19:16 -0400, Mike Lerch
<ml****************@nycap.rr.com> wrote:
I have a database with 90-odd true-false values that I need to display
on a webform as checkboxes. There are also some other values (numbers
and text) that need to be displayed.

I'm wondering the best way to do this! Do I need to individually
place and databind 90 checkboxes (and label them!) or is there a
better way? Note, this is 90 values *per row* of the
query...ultimately I'd like to be able to page through this data.

Thanks for any help.

Lerch


Nov 17 '05 #2

try with CHECKBOXLIST control, u can bind it dataset...
this will might help you.

vrushal
-----Original Message-----
A solution could be a PlaceHolder control.

Suppose that you have the result of your query in a DataReader. Youloop through each field of a row, then you add dynamic checkboxes inthe PlaceHolder. That way you can set the label and the checked valueeasily within your query.

Everything is dynamic so you don't have to modify your webform, youjust modify your query instead. Hope this helps!

Matt
On Fri, 01 Aug 2003 18:19:16 -0400, Mike Lerch
<ml****************@nycap.rr.com> wrote:
I have a database with 90-odd true-false values that I need to displayon a webform as checkboxes. There are also some other values (numbersand text) that need to be displayed.

I'm wondering the best way to do this! Do I need to individuallyplace and databind 90 checkboxes (and label them!) or is there abetter way? Note, this is 90 values *per row* of the
query...ultimately I'd like to be able to page through this data.
Thanks for any help.

Lerch


.

Nov 17 '05 #3
On Sat, 02 Aug 2003 00:51:58 GMT, Matt <me***@rocks.com> wrote:
A solution could be a PlaceHolder control.

Suppose that you have the result of your query in a DataReader. You
loop through each field of a row, then you add dynamic checkboxes in
the PlaceHolder. That way you can set the label and the checked value
easily within your query.

Everything is dynamic so you don't have to modify your webform, you
just modify your query instead. Hope this helps!


Thanks for the tip!

What I ended up doing was writing a little helper function to generate
the code for me. We had a table that listed the field name in one
column and the label (the question that was being checked yes or no)
in another, so I queried that and generated all the
<asp:checkbox......></asp:checkbox>, setting their IDs to
"chkFIELDNAME" and adding 15 to their TOP value. I pasted the output
of that right into the HTML window of the app, and that was it! I
just had to arrange them on the form.

The webform binds all the checkboxes (plus the handful of text boxes)
using this.databind() in the page load event

Here's the bulk of the code for the helper function if anyone wants to
use it!

string outstring="";
string colname="";
foreach(System.Data.DataColumn dc in
dataSet11.Tables["View2"].Columns)
{
toppos+=15;
colname=dc.ColumnName;
outstring+="<asp:CheckBox id=chk" + colname + "
style=\"Z-INDEX: 107; LEFT: 400px; POSITION: absolute; TOP: " +
toppos.ToString() + "px\" runat=\"server\" Text=\"" + colname + "\"
Height=\"4px\" Width=\"60px\" Checked='<%# DataBinder.Eval(dataSet11,
\"Tables[VIEW2].DefaultView.[0]." + colname + "\")
%>'></asp:CheckBox>\r\n" ;
}
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Anders S√łndergaard | last post: by
reply views Thread by Frank Collins | last post: by
reply views Thread by Patrick Olurotimi Ige | last post: by
3 posts views Thread by GatorBait | last post: by
1 post views Thread by Mark | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.