Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: asp.net checkbox in repeater

Results 1 to 5 of 5
Share This Thread →
  1. #1
    bs133140 is offline Registered User
    Join Date
    Nov 2003
    Posts
    5
    Rep Power
    0

    asp.net checkbox in repeater

    How can you use a checkbox in a repeater to select one or multiple records, or is there an other way to do it.
    Example: you want to click several records en then push a button delete to delte them

  2. #2
    jgreenfeld is offline Registered User
    Join Date
    Nov 2003
    Location
    Northern, VA
    Posts
    5
    Rep Power
    0
    The Repeater has an ItemTemplate property where you can add HTML code. Within the <ItemTemplate> tage, you can add <input type=checkbox> or <asp:textbox>

  3. #3
    bs133140 is offline Registered User
    Join Date
    Nov 2003
    Posts
    5
    Rep Power
    0
    Yes, but how can you tell which item is selected?

  4. #4
    bs133140 is offline Registered User
    Join Date
    Nov 2003
    Posts
    5
    Rep Power
    0
    My HTML code:
    Code:
    <asp:repeater id="rptCursus" runat="server" enableviewstate="False">
    							<HeaderTemplate>
    								<table class="table" align="left">
    									<tr style="background-color:black;color:white;font-weight:400;">
    										<td>Cursus ID</td>
    										<td>Titel</td>
    										<td>Basisduur</td>
    									</tr>
    							</HeaderTemplate>
    							<ItemTemplate>
    								<tr>
    									<td>
    										<asp:CheckBox Enabled="True" Checked="False" ID="Checkbox1" EnableViewState="true" Runat=server Text='<%# container.dataitem("cursusID")%>'>
    										</asp:CheckBox></td>
    									<td><a href='<%# String.format("CursusDetails.aspx?id={0}", container.dataitem("cursusID"))%>' target="_blank"><%# container.dataitem("titel")%></a></td>
    									<td><%# container.dataitem("basisduur")%></td>
    								</tr>
    							</ItemTemplate>
    							
    							<FooterTemplate>
    								</table>
    							</FooterTemplate>
    						</asp:repeater>
    My code behinde

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim i As Integer
    
            For i = 0 To rptCursus.Items.Count - 1
    
                Dim CurrentCheckBox As CheckBox = CType(rptCursus.Items(i).FindControl("Checkbox1"), WebControls.CheckBox)
    
    
    
    
    
                If CurrentCheckBox.Checked Then
    
                    Response.Redirect("http://localhost/elkerik/Main.aspx")
                Else
                    lblError.Text = "no"
    
                End If
    
            Next
    
        End Sub

  5. #5
    jgreenfeld is offline Registered User
    Join Date
    Nov 2003
    Location
    Northern, VA
    Posts
    5
    Rep Power
    0
    You can get the .checked property of a checkbox. That would return a boolean value.

    Also, you could try using a <asp:CheckBoxList> (similar to a control array) and fill it with checkboxes. Then you would be able to loop through the list and get the selected items.

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. ASP.NET Basics (part 1): Nothing But .Net
    By ducani in forum Development Articles
    Replies: 1
    Last Post: January 26th, 2004, 05:51 AM
  2. changing checkbox label in checkbox generated in vb.net
    By heilmank in forum HTML, JavaScript And CSS Help
    Replies: 0
    Last Post: January 21st, 2004, 01:58 PM
  3. Simple ASP.NET page to run a Windows VB.NET APP
    By oatesb in forum .NET Development
    Replies: 3
    Last Post: January 8th, 2004, 02:03 PM
  4. Problem passing a value to an asp.net page
    By PalmDrac in forum .NET Development
    Replies: 4
    Last Post: March 5th, 2003, 02:02 AM
  5. Replies: 0
    Last Post: August 10th, 2002, 07:40 AM

ASP Free Advertisers and Affiliates