473,396 Members | 1,714 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.

Creating a list of checkboxes dynamically

I'm a Classic ASP guy trying to learn .NET. I'm finding that it is making
simple things harder, at least so far.

I'm trying to re-create, from scratch, a web-based app that I did a few
years back. The old one is located at
http://www.gracearlington.com/shape/shape/

If you open the page, you'll see there are 3 or 4 sections of checkboxes.
Each of them is from a table. For example, the table called Gifts has two
columns: a numeric one called ID, and a character one called Description. To
make this section appear in ASP, I simple did this(pseudocode follows):

<tr>
<%
Do a SQL Select to get the ID and Description from the Gift table

strTempRow = 0 ----this variable is used to make it start a new <TRafter
every other <TD>
While Not RS.EOF
Response.Write "<td colspan=2><input type=checkbox name=Gift
value='"&RS.Fields("GiftID")&"'>"&RS.Fields("GiftD esc")&"</td>"
strTempRow = strTempRow + 1
If strTempRow mod 2 = 0 then%>
</tr><tr>
<%
End if
RS.MoveNext
%>
================================================== ====================

That is some really simple code, yet I cannot find a way to do the same
thing in .NET. I am using VB for language. I have copies of VWD and Studio
2005. Using SQL Server Express 2005 (for now).

I'm not asking anyone to write code for me, but I am asking for guidance. I
am not getting how to do this at all.


Mar 2 '07 #1
8 7942
"Middletree" <mi********@hottttttttmail.comwrote in message
news:OF**************@TK2MSFTNGP03.phx.gbl...
yet I cannot find a way to do the same thing in .NET.
http://www.google.co.uk/search?sourc...%3aRepeater%22
Mar 2 '07 #2
Hello Middletree,

I do something quite similar on one of my websites. I use a CheckBoxList and
populate it with a table from SQL database. The data binding code in ASP.NET
makes it pretty straightforward:

// Get a SqlDataReader from the datalayer - basically a rowset from SQL
cblCategories.DataSource = categories.SelectCategories();

// Set the DataTextField and the DataValueField's
cblCategories.DataTextField = "Category";
cblCategories.DataValueField = "CategoryID";

// DataBind the CheckBoxList to the rowset of categories
cblCategories.DataBind();

When you want to read the CheckBoxList you can do something like this:

for (int i = 0; i < cblCategories.Items.Count; i++)
{
if (cblCategories.Items[i].Selected)
{
// Do some processing
}
}

Obviously, this is C#. You'll need to figure out the VB.NET code, but it
shouldn't be difficult.
--
enjoy - brians
http://www.limbertech.com
"Middletree" wrote:
I'm a Classic ASP guy trying to learn .NET. I'm finding that it is making
simple things harder, at least so far.

I'm trying to re-create, from scratch, a web-based app that I did a few
years back. The old one is located at
http://www.gracearlington.com/shape/shape/

If you open the page, you'll see there are 3 or 4 sections of checkboxes.
Each of them is from a table. For example, the table called Gifts has two
columns: a numeric one called ID, and a character one called Description. To
make this section appear in ASP, I simple did this(pseudocode follows):

<tr>
<%
Do a SQL Select to get the ID and Description from the Gift table

strTempRow = 0 ----this variable is used to make it start a new <TRafter
every other <TD>
While Not RS.EOF
Response.Write "<td colspan=2><input type=checkbox name=Gift
value='"&RS.Fields("GiftID")&"'>"&RS.Fields("GiftD esc")&"</td>"
strTempRow = strTempRow + 1
If strTempRow mod 2 = 0 then%>
</tr><tr>
<%
End if
RS.MoveNext
%>
================================================== ====================

That is some really simple code, yet I cannot find a way to do the same
thing in .NET. I am using VB for language. I have copies of VWD and Studio
2005. Using SQL Server Express 2005 (for now).

I'm not asking anyone to write code for me, but I am asking for guidance. I
am not getting how to do this at all.


Mar 2 '07 #3


http://www.code101.com/Code101/Displ...le.aspx?cid=68
Number 1 lession, from asp to ASP.NET

NO LOOPING WITH RESPONSE.WRITE

Use a Repeater, DataList or DataGrid (1.1) ...
Use Repeater , GridView , DataList (2.0).

HEre are alot of good examples;
http://www.gridviewguy.com/CategoryD...x?categoryID=7
"Middletree" <mi********@hottttttttmail.comwrote in message
news:OF**************@TK2MSFTNGP03.phx.gbl...
I'm a Classic ASP guy trying to learn .NET. I'm finding that it is making
simple things harder, at least so far.

I'm trying to re-create, from scratch, a web-based app that I did a few
years back. The old one is located at
http://www.gracearlington.com/shape/shape/

If you open the page, you'll see there are 3 or 4 sections of checkboxes.
Each of them is from a table. For example, the table called Gifts has two
columns: a numeric one called ID, and a character one called Description.
To
make this section appear in ASP, I simple did this(pseudocode follows):

<tr>
<%
Do a SQL Select to get the ID and Description from the Gift table

strTempRow = 0 ----this variable is used to make it start a new <TRafter
every other <TD>
While Not RS.EOF
Response.Write "<td colspan=2><input type=checkbox name=Gift
value='"&RS.Fields("GiftID")&"'>"&RS.Fields("GiftD esc")&"</td>"
strTempRow = strTempRow + 1
If strTempRow mod 2 = 0 then%>
</tr><tr>
<%
End if
RS.MoveNext
%>
================================================== ====================

That is some really simple code, yet I cannot find a way to do the same
thing in .NET. I am using VB for language. I have copies of VWD and Studio
2005. Using SQL Server Express 2005 (for now).

I'm not asking anyone to write code for me, but I am asking for guidance.
I
am not getting how to do this at all.


Mar 2 '07 #4
I was not familiar with the Repeater control. Thanks!
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:u3**************@TK2MSFTNGP06.phx.gbl...
"Middletree" <mi********@hottttttttmail.comwrote in message
news:OF**************@TK2MSFTNGP03.phx.gbl...
>yet I cannot find a way to do the same thing in .NET.

http://www.google.co.uk/search?sourc...%3aRepeater%22

Mar 2 '07 #5
>
http://www.code101.com/Code101/Displ...le.aspx?cid=68
I didn't really understand this page.
NO LOOPING WITH RESPONSE.WRITE
Thanks. Good to know.
Use Repeater , GridView , DataList (2.0).
I was trying to use the latter 2 before I posted this. Now I know about the
repeater, so I'll see what I can do with that.
>
HEre are alot of good examples;
http://www.gridviewguy.com/CategoryD...x?categoryID=7
I'll check it out. Thanks.

Mar 2 '07 #6
"Middletree" <mi********@hottttttttmail.comwrote in message
news:uV**************@TK2MSFTNGP06.phx.gbl...
I was not familiar with the Repeater control. Thanks!
No problem...

And I hope you won't take this the wrong way (you said yourself that you are
an ASP.NET newbie...) but getting hold of a beginner's guide to ASP.NET will
be of huge help to you... ASP.NET is very different from ASP, as you've no
doubt discovered... Until you have a grasp of the basics, you're going to
find it all very daunting and frustrating...

Something like this:
http://www.amazon.com/ASP-NET-All-Re...2870659&sr=8-1

Alternatively, there are some excellent beginners' tutorials available on
the web...
Mar 2 '07 #7
getting hold of a beginner's guide to ASP.NET will be of huge help to you.

Oh, yeah, I knew that, and in fact, I have been going through a couple of
books for newbies. I just hadn't seen anything that helps me with this
particular task in any of the books.

thanks
Mar 2 '07 #8
"Middletree" <mi********@hottttttttmail.comwrote in message
news:ue**************@TK2MSFTNGP03.phx.gbl...
>getting hold of a beginner's guide to ASP.NET will be of huge help to
you.

Oh, yeah, I knew that, and in fact, I have been going through a couple of
books for newbies. I just hadn't seen anything that helps me with this
particular task in any of the books.
That's excellent! You obviously know what you need to do, and are doing it.
Your original request for assistance was clear and well phrased, so I'm sure
you'll be up to speed on ASP.NET in no time at all...
Mar 2 '07 #9

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

Similar topics

0
by: Frank Collins | last post by:
Can anyone point me to some good examples on the web of using values from dynamically created checkboxes on forms in ASP, particularly relating to INSERTING those values into a SQL or Access...
10
by: Steve | last post by:
I'm not sure if I should be using tables here to structure the layout or if CSS is okay. I have a data entry form in which I have floated the labels to one side, and given them a specific width....
3
by: Ondernemer | last post by:
Hi guys, On my page I dynamically create different checkboxes. <input type="checkbox" name="ch1" value="some value"> option 1 <input type="checkbox" name="ch2" value="some value"> option 2...
1
by: babu17 | last post by:
hi, i have a list of checkboxes, the number of checkboxes is dynamic. All the checkboxes have same name. i am trying to get the length of selected checkboxes. <input type=checkbox name=name1...
5
by: SalamElias | last post by:
I am creating several chkBoxes dynamically and assigning an event handler in the Page_load as foillows ***************************** Dim chkCatOption As CheckBox = New CheckBox chkCatOption.Text...
2
by: somaskarthic | last post by:
Hi In my php code , i dynamically created table rows on button click event. Each row contain 3 selectboxes, 7 checkboxes . On each click of these elements i need to submit the form and save the...
1
by: Petyr David | last post by:
Current: web page has hard coded directories (using checkboxes) user may choose to search for files matching a pattern they enter in text box. Perl is used to search for files and to format HTML...
9
by: Sebarry | last post by:
Hi, I've put together a little test page to create checkboxes each time a button is clicked. The check button is created and should be appended to the form, but when the post is submitted the...
14
by: tdahsu | last post by:
I have twenty-five checkboxes I need to create (don't ask): self.checkbox1 = ... self.checkbox2 = ... .. .. .. self.checkbox25 = ... Right now, my code has 25 lines in it, one for each...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.