[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to Display CheckBoxes in ASP.NET

Posted on 2005-05-16
7
Medium Priority
?
414 Views
Last Modified: 2008-08-20
Hi everyone,

I do this in ASP:

<%
Do Until rs. EOF
    %><input type="checkbox" name="chkDelete" value="<%=rs.Fields("App_ID")%>"><br><%
    rs.MoveNext
Loop
%>

What would be the equivalent of this in ASP.NET?  I already have a repeater control and a dataview which I assign to the repeater control.

Thank you so much,


Jazon Samillano from Jacksonville, Florida
0
Comment
Question by:piratepatrol
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:dharmesh_amity
ID: 14013636
<asp:Repeater id=Repeater1 runat="server">
    <ItemTemplate>
      <input type="checkbox" name="chkDelete" value='<%#DataBinder.Eval(Container, "DataItem.App_ID")%>'>
    </ItemTemplate>            
</asp:Repeater>

No need to add any other code.

Just do this in page_load event of your page

Repeater1.DataSource = yourdataview ' Your dataview object
Repeater1.DataBind()
0
 
LVL 3

Author Comment

by:piratepatrol
ID: 14013692
I actually wanted the checkbox to be a web server control so that I can attach an event to it.  When I use the <asp:CheckBox control, it doesn't have an attribute called "value".  
0
 
LVL 6

Expert Comment

by:dharmesh_amity
ID: 14013787
<asp:Repeater id=Repeater1 runat="server">
    <ItemTemplate>
       <asp:CheckBox id=CheckBox1 runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.App_ID")%>'></asp:CheckBox>
    </ItemTemplate>            
    </asp:Repeater>

The problem with chekbox server control is that ASP.NET will change the name if the checkbox is in the repeater control. So if you want the checkboxes to be grouped by name then you will have problem otherwise you are all set.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Assisted Solution

by:dharmesh_amity
dharmesh_amity earned 2000 total points
ID: 14013898
I am sorry I misunderstood the value field of checkbox. Yes you are right there is nothing for value field in Checkbox control. You can do it by putting a hidden field. The text will show up with the checkbox.

Anyway ASP.NET changes the name of the checkbox and things will not work as you expect. So It would be better to use html checkbox instead of server control.

If you are trying to implement event like the web control checkbox with AutoPostBack=true you can do that by using some javascript where you can set a hidden field with the a value.

0
 
LVL 3

Author Comment

by:piratepatrol
ID: 14018835
What's Microsoft reason for not giving the CheckBox web server control the value attribute?
0
 
LVL 6

Accepted Solution

by:
dharmesh_amity earned 2000 total points
ID: 14018926
The Checkbox is put inside <span> tag when the CheckBox is rendered to the browser. There are other problems too because of this. If you want to change the style of the checkbox it really changes the style of the span element. The checkbox is a combination of text besides it and the checkbox. Yes you are right its frustrating sometimes, but whenever I have this kind of requirement I use the html checkbox instead of the server control.

Try to group these server control checkboxes you will go nuts, unless you use checkbox list, but then you cannot have them in repeater, or datagrid controls where you want to put only one checkbox per row.
0
 
LVL 3

Author Comment

by:piratepatrol
ID: 14019182
Hum, what a pain.  Thanks, dude.  
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question