Link to home
Start Free TrialLog in
Avatar of piratepatrol
piratepatrolFlag for United States of America

asked on

How to Display CheckBoxes in ASP.NET

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
Avatar of dharmesh_amity
dharmesh_amity

<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()
Avatar of piratepatrol

ASKER

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".  
<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.
SOLUTION
Avatar of dharmesh_amity
dharmesh_amity

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What's Microsoft reason for not giving the CheckBox web server control the value attribute?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hum, what a pain.  Thanks, dude.