Best practice for checkboxes in repeaters

Discussion in 'ASP .Net Web Controls' started by Thomas Nielsen [AM Production A/S], Nov 18, 2003.

  1. I've been struggling (for too much) with checkboxes in repeaters. It's a
    mystery to me why the <asp:checkbox> control does not expose a value
    property for the checkbox, so that you would be able to identify the
    checkbox on postback.

    Can anyone comment on best practices for working with checkboxes inside
    repeaters?.

    Thanks,

    Thomas
    Thomas Nielsen [AM Production A/S], Nov 18, 2003
    #1
    1. Advertising

  2. Hi Thomas,

    I put a checkbox on a repeater and added a button (outside of the
    repeater). In the button's server-side click event, I iterated through the
    repeater to get the values of each check box. Here's a code snippet.

    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 Repeater1.Items.Count - 1
    Response.Write(CType(Repeater1.Items(i).Controls(1),
    WebControls.CheckBox).Checked & "<br>")
    Next i
    End Sub

    In my case the check box was at position Controls(1). You may need to
    adjust that number.

    Does this answer your question?

    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    http://www.microsoft.com/protect site and perform the three straightforward
    steps listed to improve your computer’s security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > From: "Thomas Nielsen [AM Production A/S]" <>
    > Subject: Best practice for checkboxes in repeaters
    > Date: Tue, 18 Nov 2003 12:32:28 +0100
    > Lines: 19
    > X-Priority: 3
    > X-MSMail-Priority: Normal
    > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > Message-ID: <>
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > NNTP-Posting-Host: 195.41.96.158
    > Path:

    cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
    phx.gbl
    > Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webcontrols:16260
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    >
    > I've been struggling (for too much) with checkboxes in repeaters. It's a
    > mystery to me why the <asp:checkbox> control does not expose a value
    > property for the checkbox, so that you would be able to identify the
    > checkbox on postback.
    >
    > Can anyone comment on best practices for working with checkboxes inside
    > repeaters?.
    >
    > Thanks,
    >
    > Thomas
    >
    >
    >
    >
    >
    >
    >
    >
    >
    Mike Moore [MSFT], Nov 18, 2003
    #2
    1. Advertising

  3. Hi Mike,

    It does not, no - What you are getting from your iteration is a boolean
    telling you whether or not the checkbox has been checked, not exactly WHAT
    is checked.
    If my repeater contained eg. a list of records i wanted to delete from, I
    would have to store the recordset i initially bound to the repeater, and use
    that in connection with the index you're finding, to find out e.g. the
    unique ID of the record(s) selected.

    Let me give you an ASP example: In asp, I would render a list of records to
    the client, with checkboxes named "checked_delete_id_XYX", with XYX being
    the unique ID of the record i wanted to delete. Upon postback, i would
    iterate through the forms collection to find all checkboxes starting with
    "checked_delete_id_", and run my "business logic" (in this case, deleting a
    record) on this ID.

    Also, you use an index into Controls (Controls(X)), which i consider bad
    practice .. It's hard to read unless you know exactly how your codefront
    looks, and if someone was to add an additional checkbox to the codefront,
    the code would still work but the result completely wrong.

    ...Or is my approach just completely wrong? :)

    Cheers,

    /Thomas






    ""Mike Moore [MSFT]"" <> wrote in message
    news:...
    > Hi Thomas,
    >
    > I put a checkbox on a repeater and added a button (outside of the
    > repeater). In the button's server-side click event, I iterated through the
    > repeater to get the values of each check box. Here's a code snippet.
    >
    > 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 Repeater1.Items.Count - 1
    > Response.Write(CType(Repeater1.Items(i).Controls(1),
    > WebControls.CheckBox).Checked & "<br>")
    > Next i
    > End Sub
    >
    > In my case the check box was at position Controls(1). You may need to
    > adjust that number.
    >
    > Does this answer your question?
    >
    > Thank you, Mike
    > Microsoft, ASP.NET Support Professional
    >
    > Microsoft highly recommends to all of our customers that they visit the
    > http://www.microsoft.com/protect site and perform the three

    straightforward
    > steps listed to improve your computer's security.
    >
    > This posting is provided "AS IS", with no warranties, and confers no

    rights.
    >
    >
    > --------------------
    > > From: "Thomas Nielsen [AM Production A/S]" <>
    > > Subject: Best practice for checkboxes in repeaters
    > > Date: Tue, 18 Nov 2003 12:32:28 +0100
    > > Lines: 19
    > > X-Priority: 3
    > > X-MSMail-Priority: Normal
    > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > Message-ID: <>
    > > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > NNTP-Posting-Host: 195.41.96.158
    > > Path:

    >

    cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
    > phx.gbl
    > > Xref: cpmsftngxa06.phx.gbl

    > microsoft.public.dotnet.framework.aspnet.webcontrols:16260
    > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    > >
    > > I've been struggling (for too much) with checkboxes in repeaters. It's a
    > > mystery to me why the <asp:checkbox> control does not expose a value
    > > property for the checkbox, so that you would be able to identify the
    > > checkbox on postback.
    > >
    > > Can anyone comment on best practices for working with checkboxes inside
    > > repeaters?.
    > >
    > > Thanks,
    > >
    > > Thomas
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >

    >
    Thomas Nielsen [AM Production A/S], Nov 19, 2003
    #3
  4. Hi Thomas,

    I tried lots of experiments and found that I could not add a value
    attribute to the checkbox webcontrol. I was able to do so with the HTML
    checkbox control. However, since the checkbox is in a repeater, its name on
    the client is modified for each instance. I was not able to create a label
    control that matched up with each instance.

    It looks like the easiest way to store the value associated with the check
    box is to add a hidden field to the repeater and store the value there.

    I hope this helps.

    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    http://www.microsoft.com/protect site and perform the three straightforward
    steps listed to improve your computer’s security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > From: "Thomas Nielsen [AM Production A/S]" <>
    > References: <>

    <>
    > Subject: Re: Best practice for checkboxes in repeaters
    > Date: Wed, 19 Nov 2003 09:12:36 +0100
    > Lines: 111
    > X-Priority: 3
    > X-MSMail-Priority: Normal
    > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > Message-ID: <>
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > NNTP-Posting-Host: 195.41.96.158
    > Path:

    cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.
    phx.gbl
    > Xref: cpmsftngxa06.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webcontrols:16287
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    >
    >
    > Hi Mike,
    >
    > It does not, no - What you are getting from your iteration is a boolean
    > telling you whether or not the checkbox has been checked, not exactly WHAT
    > is checked.
    > If my repeater contained eg. a list of records i wanted to delete from, I
    > would have to store the recordset i initially bound to the repeater, and

    use
    > that in connection with the index you're finding, to find out e.g. the
    > unique ID of the record(s) selected.
    >
    > Let me give you an ASP example: In asp, I would render a list of records

    to
    > the client, with checkboxes named "checked_delete_id_XYX", with XYX being
    > the unique ID of the record i wanted to delete. Upon postback, i would
    > iterate through the forms collection to find all checkboxes starting with
    > "checked_delete_id_", and run my "business logic" (in this case, deleting

    a
    > record) on this ID.
    >
    > Also, you use an index into Controls (Controls(X)), which i consider bad
    > practice .. It's hard to read unless you know exactly how your codefront
    > looks, and if someone was to add an additional checkbox to the codefront,
    > the code would still work but the result completely wrong.
    >
    > ..Or is my approach just completely wrong? :)
    >
    > Cheers,
    >
    > /Thomas
    >
    >
    >
    >
    >
    >
    > ""Mike Moore [MSFT]"" <> wrote in message
    > news:...
    > > Hi Thomas,
    > >
    > > I put a checkbox on a repeater and added a button (outside of the
    > > repeater). In the button's server-side click event, I iterated through

    the
    > > repeater to get the values of each check box. Here's a code snippet.
    > >
    > > 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 Repeater1.Items.Count - 1
    > > Response.Write(CType(Repeater1.Items(i).Controls(1),
    > > WebControls.CheckBox).Checked & "<br>")
    > > Next i
    > > End Sub
    > >
    > > In my case the check box was at position Controls(1). You may need to
    > > adjust that number.
    > >
    > > Does this answer your question?
    > >
    > > Thank you, Mike
    > > Microsoft, ASP.NET Support Professional
    > >
    > > Microsoft highly recommends to all of our customers that they visit the
    > > http://www.microsoft.com/protect site and perform the three

    > straightforward
    > > steps listed to improve your computer's security.
    > >
    > > This posting is provided "AS IS", with no warranties, and confers no

    > rights.
    > >
    > >
    > > --------------------
    > > > From: "Thomas Nielsen [AM Production A/S]" <>
    > > > Subject: Best practice for checkboxes in repeaters
    > > > Date: Tue, 18 Nov 2003 12:32:28 +0100
    > > > Lines: 19
    > > > X-Priority: 3
    > > > X-MSMail-Priority: Normal
    > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > Message-ID: <>
    > > > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > > NNTP-Posting-Host: 195.41.96.158
    > > > Path:

    > >

    >

    cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
    > > phx.gbl
    > > > Xref: cpmsftngxa06.phx.gbl

    > > microsoft.public.dotnet.framework.aspnet.webcontrols:16260
    > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > >
    > > > I've been struggling (for too much) with checkboxes in repeaters.

    It's a
    > > > mystery to me why the <asp:checkbox> control does not expose a value
    > > > property for the checkbox, so that you would be able to identify the
    > > > checkbox on postback.
    > > >
    > > > Can anyone comment on best practices for working with checkboxes

    inside
    > > > repeaters?.
    > > >
    > > > Thanks,
    > > >
    > > > Thomas
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >

    > >

    >
    >
    >
    Mike Moore [MSFT], Nov 19, 2003
    #4
  5. Hi Mike,

    That's the solution I have used a couple of times too. It's just very hard
    for me to accept that this is the best way to use the checkbox control, when
    I consider the amount of times this functionality is used by everyone.

    In effect, this means the checkbox control is completely useless to me in
    real-world scenaries. I'm surprised this particular control wasn't designed
    more elegantly.

    /Thomas


    ""Mike Moore [MSFT]"" <> wrote in message
    news:...
    > Hi Thomas,
    >
    > I tried lots of experiments and found that I could not add a value
    > attribute to the checkbox webcontrol. I was able to do so with the HTML
    > checkbox control. However, since the checkbox is in a repeater, its name

    on
    > the client is modified for each instance. I was not able to create a label
    > control that matched up with each instance.
    >
    > It looks like the easiest way to store the value associated with the check
    > box is to add a hidden field to the repeater and store the value there.
    >
    > I hope this helps.
    >
    > Thank you, Mike
    > Microsoft, ASP.NET Support Professional
    >
    > Microsoft highly recommends to all of our customers that they visit the
    > http://www.microsoft.com/protect site and perform the three

    straightforward
    > steps listed to improve your computer's security.
    >
    > This posting is provided "AS IS", with no warranties, and confers no

    rights.
    >
    >
    > --------------------
    > > From: "Thomas Nielsen [AM Production A/S]" <>
    > > References: <>

    > <>
    > > Subject: Re: Best practice for checkboxes in repeaters
    > > Date: Wed, 19 Nov 2003 09:12:36 +0100
    > > Lines: 111
    > > X-Priority: 3
    > > X-MSMail-Priority: Normal
    > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > Message-ID: <>
    > > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > NNTP-Posting-Host: 195.41.96.158
    > > Path:

    >

    cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.
    > phx.gbl
    > > Xref: cpmsftngxa06.phx.gbl

    > microsoft.public.dotnet.framework.aspnet.webcontrols:16287
    > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    > >
    > >
    > > Hi Mike,
    > >
    > > It does not, no - What you are getting from your iteration is a boolean
    > > telling you whether or not the checkbox has been checked, not exactly

    WHAT
    > > is checked.
    > > If my repeater contained eg. a list of records i wanted to delete from,

    I
    > > would have to store the recordset i initially bound to the repeater, and

    > use
    > > that in connection with the index you're finding, to find out e.g. the
    > > unique ID of the record(s) selected.
    > >
    > > Let me give you an ASP example: In asp, I would render a list of records

    > to
    > > the client, with checkboxes named "checked_delete_id_XYX", with XYX

    being
    > > the unique ID of the record i wanted to delete. Upon postback, i would
    > > iterate through the forms collection to find all checkboxes starting

    with
    > > "checked_delete_id_", and run my "business logic" (in this case,

    deleting
    > a
    > > record) on this ID.
    > >
    > > Also, you use an index into Controls (Controls(X)), which i consider bad
    > > practice .. It's hard to read unless you know exactly how your codefront
    > > looks, and if someone was to add an additional checkbox to the

    codefront,
    > > the code would still work but the result completely wrong.
    > >
    > > ..Or is my approach just completely wrong? :)
    > >
    > > Cheers,
    > >
    > > /Thomas
    > >
    > >
    > >
    > >
    > >
    > >
    > > ""Mike Moore [MSFT]"" <> wrote in message
    > > news:...
    > > > Hi Thomas,
    > > >
    > > > I put a checkbox on a repeater and added a button (outside of the
    > > > repeater). In the button's server-side click event, I iterated through

    > the
    > > > repeater to get the values of each check box. Here's a code snippet.
    > > >
    > > > 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 Repeater1.Items.Count - 1
    > > > Response.Write(CType(Repeater1.Items(i).Controls(1),
    > > > WebControls.CheckBox).Checked & "<br>")
    > > > Next i
    > > > End Sub
    > > >
    > > > In my case the check box was at position Controls(1). You may need to
    > > > adjust that number.
    > > >
    > > > Does this answer your question?
    > > >
    > > > Thank you, Mike
    > > > Microsoft, ASP.NET Support Professional
    > > >
    > > > Microsoft highly recommends to all of our customers that they visit

    the
    > > > http://www.microsoft.com/protect site and perform the three

    > > straightforward
    > > > steps listed to improve your computer's security.
    > > >
    > > > This posting is provided "AS IS", with no warranties, and confers no

    > > rights.
    > > >
    > > >
    > > > --------------------
    > > > > From: "Thomas Nielsen [AM Production A/S]" <>
    > > > > Subject: Best practice for checkboxes in repeaters
    > > > > Date: Tue, 18 Nov 2003 12:32:28 +0100
    > > > > Lines: 19
    > > > > X-Priority: 3
    > > > > X-MSMail-Priority: Normal
    > > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > > Message-ID: <>
    > > > > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > > > NNTP-Posting-Host: 195.41.96.158
    > > > > Path:
    > > >

    > >

    >

    cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
    > > > phx.gbl
    > > > > Xref: cpmsftngxa06.phx.gbl
    > > > microsoft.public.dotnet.framework.aspnet.webcontrols:16260
    > > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > > >
    > > > > I've been struggling (for too much) with checkboxes in repeaters.

    > It's a
    > > > > mystery to me why the <asp:checkbox> control does not expose a value
    > > > > property for the checkbox, so that you would be able to identify the
    > > > > checkbox on postback.
    > > > >
    > > > > Can anyone comment on best practices for working with checkboxes

    > inside
    > > > > repeaters?.
    > > > >
    > > > > Thanks,
    > > > >
    > > > > Thomas
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > >

    > >
    > >
    > >

    >
    Thomas Nielsen [AM Production A/S], Nov 20, 2003
    #5
  6. Hi Thomas,

    I'm sorry that the check box control does not have all the features that
    you want. I have forwarded this as a feature request.

    Thank you, Mike
    Microsoft, ASP.NET Support Professional

    Microsoft highly recommends to all of our customers that they visit the
    http://www.microsoft.com/protect site and perform the three straightforward
    steps listed to improve your computer’s security.

    This posting is provided "AS IS", with no warranties, and confers no rights.


    --------------------
    > From: "Thomas Nielsen [AM Production A/S]" <>
    > References: <>

    <>
    <>
    <>
    > Subject: Re: Best practice for checkboxes in repeaters
    > Date: Thu, 20 Nov 2003 09:23:32 +0100
    > Lines: 194
    > X-Priority: 3
    > X-MSMail-Priority: Normal
    > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > Message-ID: <#>
    > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > NNTP-Posting-Host: 195.41.96.158
    > Path:

    cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
    .phx.gbl!TK2MSFTNGP09.phx.gbl
    > Xref: cpmsftngxa07.phx.gbl

    microsoft.public.dotnet.framework.aspnet.webcontrols:16236
    > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    >
    > Hi Mike,
    >
    > That's the solution I have used a couple of times too. It's just very hard
    > for me to accept that this is the best way to use the checkbox control,

    when
    > I consider the amount of times this functionality is used by everyone.
    >
    > In effect, this means the checkbox control is completely useless to me in
    > real-world scenaries. I'm surprised this particular control wasn't

    designed
    > more elegantly.
    >
    > /Thomas
    >
    >
    > ""Mike Moore [MSFT]"" <> wrote in message
    > news:...
    > > Hi Thomas,
    > >
    > > I tried lots of experiments and found that I could not add a value
    > > attribute to the checkbox webcontrol. I was able to do so with the HTML
    > > checkbox control. However, since the checkbox is in a repeater, its name

    > on
    > > the client is modified for each instance. I was not able to create a

    label
    > > control that matched up with each instance.
    > >
    > > It looks like the easiest way to store the value associated with the

    check
    > > box is to add a hidden field to the repeater and store the value there.
    > >
    > > I hope this helps.
    > >
    > > Thank you, Mike
    > > Microsoft, ASP.NET Support Professional
    > >
    > > Microsoft highly recommends to all of our customers that they visit the
    > > http://www.microsoft.com/protect site and perform the three

    > straightforward
    > > steps listed to improve your computer's security.
    > >
    > > This posting is provided "AS IS", with no warranties, and confers no

    > rights.
    > >
    > >
    > > --------------------
    > > > From: "Thomas Nielsen [AM Production A/S]" <>
    > > > References: <>

    > > <>
    > > > Subject: Re: Best practice for checkboxes in repeaters
    > > > Date: Wed, 19 Nov 2003 09:12:36 +0100
    > > > Lines: 111
    > > > X-Priority: 3
    > > > X-MSMail-Priority: Normal
    > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > Message-ID: <>
    > > > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > > NNTP-Posting-Host: 195.41.96.158
    > > > Path:

    > >

    >

    cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.
    > > phx.gbl
    > > > Xref: cpmsftngxa06.phx.gbl

    > > microsoft.public.dotnet.framework.aspnet.webcontrols:16287
    > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > >
    > > >
    > > > Hi Mike,
    > > >
    > > > It does not, no - What you are getting from your iteration is a

    boolean
    > > > telling you whether or not the checkbox has been checked, not exactly

    > WHAT
    > > > is checked.
    > > > If my repeater contained eg. a list of records i wanted to delete

    from,
    > I
    > > > would have to store the recordset i initially bound to the repeater,

    and
    > > use
    > > > that in connection with the index you're finding, to find out e.g. the
    > > > unique ID of the record(s) selected.
    > > >
    > > > Let me give you an ASP example: In asp, I would render a list of

    records
    > > to
    > > > the client, with checkboxes named "checked_delete_id_XYX", with XYX

    > being
    > > > the unique ID of the record i wanted to delete. Upon postback, i would
    > > > iterate through the forms collection to find all checkboxes starting

    > with
    > > > "checked_delete_id_", and run my "business logic" (in this case,

    > deleting
    > > a
    > > > record) on this ID.
    > > >
    > > > Also, you use an index into Controls (Controls(X)), which i consider

    bad
    > > > practice .. It's hard to read unless you know exactly how your

    codefront
    > > > looks, and if someone was to add an additional checkbox to the

    > codefront,
    > > > the code would still work but the result completely wrong.
    > > >
    > > > ..Or is my approach just completely wrong? :)
    > > >
    > > > Cheers,
    > > >
    > > > /Thomas
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > > ""Mike Moore [MSFT]"" <> wrote in message
    > > > news:...
    > > > > Hi Thomas,
    > > > >
    > > > > I put a checkbox on a repeater and added a button (outside of the
    > > > > repeater). In the button's server-side click event, I iterated

    through
    > > the
    > > > > repeater to get the values of each check box. Here's a code snippet.
    > > > >
    > > > > 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 Repeater1.Items.Count - 1
    > > > > Response.Write(CType(Repeater1.Items(i).Controls(1),
    > > > > WebControls.CheckBox).Checked & "<br>")
    > > > > Next i
    > > > > End Sub
    > > > >
    > > > > In my case the check box was at position Controls(1). You may need

    to
    > > > > adjust that number.
    > > > >
    > > > > Does this answer your question?
    > > > >
    > > > > Thank you, Mike
    > > > > Microsoft, ASP.NET Support Professional
    > > > >
    > > > > Microsoft highly recommends to all of our customers that they visit

    > the
    > > > > http://www.microsoft.com/protect site and perform the three
    > > > straightforward
    > > > > steps listed to improve your computer's security.
    > > > >
    > > > > This posting is provided "AS IS", with no warranties, and confers no
    > > > rights.
    > > > >
    > > > >
    > > > > --------------------
    > > > > > From: "Thomas Nielsen [AM Production A/S]"

    <>
    > > > > > Subject: Best practice for checkboxes in repeaters
    > > > > > Date: Tue, 18 Nov 2003 12:32:28 +0100
    > > > > > Lines: 19
    > > > > > X-Priority: 3
    > > > > > X-MSMail-Priority: Normal
    > > > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > > > Message-ID: <>
    > > > > > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > > > > NNTP-Posting-Host: 195.41.96.158
    > > > > > Path:
    > > > >
    > > >

    > >

    >

    cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
    > > > > phx.gbl
    > > > > > Xref: cpmsftngxa06.phx.gbl
    > > > > microsoft.public.dotnet.framework.aspnet.webcontrols:16260
    > > > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > > > >
    > > > > > I've been struggling (for too much) with checkboxes in repeaters.

    > > It's a
    > > > > > mystery to me why the <asp:checkbox> control does not expose a

    value
    > > > > > property for the checkbox, so that you would be able to identify

    the
    > > > > > checkbox on postback.
    > > > > >
    > > > > > Can anyone comment on best practices for working with checkboxes

    > > inside
    > > > > > repeaters?.
    > > > > >
    > > > > > Thanks,
    > > > > >
    > > > > > Thomas
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > > >
    > > > >
    > > >
    > > >
    > > >

    > >

    >
    >
    >
    Mike Moore [MSFT], Nov 21, 2003
    #6
  7. Thomas Nielsen [AM Production A/S]

    Dave Truxall Guest

    Why not simply create your own checkbox, inheriting the current
    version and adding the property you want?

    Public Class RepeaterCheckBox
    Inherits CheckBox

    Property Value() As String

    Get
    Return CType(ViewState("value"), String)
    End Get

    Set(ByVal Input As String)
    ViewState("value") = Input
    End Set

    End Property

    End Class

    ("Mike Moore [MSFT]") wrote in message news:<>...
    > Hi Thomas,
    >
    > I'm sorry that the check box control does not have all the features that
    > you want. I have forwarded this as a feature request.
    >
    > Thank you, Mike
    > Microsoft, ASP.NET Support Professional
    >
    > Microsoft highly recommends to all of our customers that they visit the
    > http://www.microsoft.com/protect site and perform the three straightforward
    > steps listed to improve your computer?s security.
    >
    > This posting is provided "AS IS", with no warranties, and confers no rights.
    >
    >
    > --------------------
    > > From: "Thomas Nielsen [AM Production A/S]" <>
    > > References: <>

    > <>
    > <>
    > <>
    > > Subject: Re: Best practice for checkboxes in repeaters
    > > Date: Thu, 20 Nov 2003 09:23:32 +0100
    > > Lines: 194
    > > X-Priority: 3
    > > X-MSMail-Priority: Normal
    > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > Message-ID: <#>
    > > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > NNTP-Posting-Host: 195.41.96.158
    > > Path:

    > cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
    > phx.gbl!TK2MSFTNGP09.phx.gbl
    > > Xref: cpmsftngxa07.phx.gbl

    > microsoft.public.dotnet.framework.aspnet.webcontrols:16236
    > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    > >
    > > Hi Mike,
    > >
    > > That's the solution I have used a couple of times too. It's just very hard
    > > for me to accept that this is the best way to use the checkbox control,

    > when
    > > I consider the amount of times this functionality is used by everyone.
    > >
    > > In effect, this means the checkbox control is completely useless to me in
    > > real-world scenaries. I'm surprised this particular control wasn't

    > designed
    > > more elegantly.
    > >
    > > /Thomas
    > >
    > >
    > > ""Mike Moore [MSFT]"" <> wrote in message
    > > news:...
    > > > Hi Thomas,
    > > >
    > > > I tried lots of experiments and found that I could not add a value
    > > > attribute to the checkbox webcontrol. I was able to do so with the HTML
    > > > checkbox control. However, since the checkbox is in a repeater, its name

    > on
    > > > the client is modified for each instance. I was not able to create a

    > label
    > > > control that matched up with each instance.
    > > >
    > > > It looks like the easiest way to store the value associated with the

    > check
    > > > box is to add a hidden field to the repeater and store the value there.
    > > >
    > > > I hope this helps.
    > > >
    > > > Thank you, Mike
    > > > Microsoft, ASP.NET Support Professional
    > > >
    > > > Microsoft highly recommends to all of our customers that they visit the
    > > > http://www.microsoft.com/protect site and perform the three

    > straightforward
    > > > steps listed to improve your computer's security.
    > > >
    > > > This posting is provided "AS IS", with no warranties, and confers no

    > rights.
    > > >
    > > >
    > > > --------------------
    > > > > From: "Thomas Nielsen [AM Production A/S]" <>
    > > > > References: <>

    > <>
    > > > > Subject: Re: Best practice for checkboxes in repeaters
    > > > > Date: Wed, 19 Nov 2003 09:12:36 +0100
    > > > > Lines: 111
    > > > > X-Priority: 3
    > > > > X-MSMail-Priority: Normal
    > > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > > Message-ID: <>
    > > > > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > > > NNTP-Posting-Host: 195.41.96.158
    > > > > Path:
    > > >

    > >

    > cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.
    > > > phx.gbl
    > > > > Xref: cpmsftngxa06.phx.gbl

    > microsoft.public.dotnet.framework.aspnet.webcontrols:16287
    > > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > > >
    > > > >
    > > > > Hi Mike,
    > > > >
    > > > > It does not, no - What you are getting from your iteration is a

    > boolean
    > > > > telling you whether or not the checkbox has been checked, not exactly

    > WHAT
    > > > > is checked.
    > > > > If my repeater contained eg. a list of records i wanted to delete

    > from,
    > I
    > > > > would have to store the recordset i initially bound to the repeater,

    > and
    > use
    > > > > that in connection with the index you're finding, to find out e.g. the
    > > > > unique ID of the record(s) selected.
    > > > >
    > > > > Let me give you an ASP example: In asp, I would render a list of

    > records
    > to
    > > > > the client, with checkboxes named "checked_delete_id_XYX", with XYX

    > being
    > > > > the unique ID of the record i wanted to delete. Upon postback, i would
    > > > > iterate through the forms collection to find all checkboxes starting

    > with
    > > > > "checked_delete_id_", and run my "business logic" (in this case,

    > deleting
    > a
    > > > > record) on this ID.
    > > > >
    > > > > Also, you use an index into Controls (Controls(X)), which i consider

    > bad
    > > > > practice .. It's hard to read unless you know exactly how your

    > codefront
    > > > > looks, and if someone was to add an additional checkbox to the

    > codefront,
    > > > > the code would still work but the result completely wrong.
    > > > >
    > > > > ..Or is my approach just completely wrong? :)
    > > > >
    > > > > Cheers,
    > > > >
    > > > > /Thomas
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > > ""Mike Moore [MSFT]"" <> wrote in message
    > > > > news:...
    > > > > > Hi Thomas,
    > > > > >
    > > > > > I put a checkbox on a repeater and added a button (outside of the
    > > > > > repeater). In the button's server-side click event, I iterated

    > through
    > the
    > > > > > repeater to get the values of each check box. Here's a code snippet.
    > > > > >
    > > > > > 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 Repeater1.Items.Count - 1
    > > > > > Response.Write(CType(Repeater1.Items(i).Controls(1),
    > > > > > WebControls.CheckBox).Checked & "<br>")
    > > > > > Next i
    > > > > > End Sub
    > > > > >
    > > > > > In my case the check box was at position Controls(1). You may need

    > to
    > > > > > adjust that number.
    > > > > >
    > > > > > Does this answer your question?
    > > > > >
    > > > > > Thank you, Mike
    > > > > > Microsoft, ASP.NET Support Professional
    > > > > >
    > > > > > Microsoft highly recommends to all of our customers that they visit

    > the
    > > > > > http://www.microsoft.com/protect site and perform the three

    > straightforward
    > > > > > steps listed to improve your computer's security.
    > > > > >
    > > > > > This posting is provided "AS IS", with no warranties, and confers no

    > rights.
    > > > > >
    > > > > >
    > > > > > --------------------
    > > > > > > From: "Thomas Nielsen [AM Production A/S]"

    > <>
    > > > > > > Subject: Best practice for checkboxes in repeaters
    > > > > > > Date: Tue, 18 Nov 2003 12:32:28 +0100
    > > > > > > Lines: 19
    > > > > > > X-Priority: 3
    > > > > > > X-MSMail-Priority: Normal
    > > > > > > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    > > > > > > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    > > > > > > Message-ID: <>
    > > > > > > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > > > > > NNTP-Posting-Host: 195.41.96.158
    > > > > > > Path:
    > > > > >
    > > > >
    > > >

    > >

    > cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
    > > > > > phx.gbl
    > > > > > > Xref: cpmsftngxa06.phx.gbl

    > microsoft.public.dotnet.framework.aspnet.webcontrols:16260
    > > > > > > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    > > > > > >
    > > > > > > I've been struggling (for too much) with checkboxes in repeaters.

    > It's a
    > > > > > > mystery to me why the <asp:checkbox> control does not expose a

    > value
    > > > > > > property for the checkbox, so that you would be able to identify

    > the
    > > > > > > checkbox on postback.
    > > > > > >
    > > > > > > Can anyone comment on best practices for working with checkboxes

    > inside
    > > > > > > repeaters?.
    > > > > > >
    > > > > > > Thanks,
    > > > > > >
    > > > > > > Thomas
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > > >
    > > > > >
    > > > >
    > > > >
    > > > >
    > > >

    > >
    > >
    > >
    Dave Truxall, Dec 10, 2003
    #7
  8. Thomas Nielsen [AM Production A/S]

    Adam Guest

    Maybe I'm not getting what you guys are saying, but you can add any
    attribute you want to any asp.net control. For instance on my
    checkboxes I can simply do this:

    cbxMyCheckbox.Attributes["value"] = "whatever";

    Then on the postback I can get the value back out like this:

    string val = cbxMyCheckbox.Attributes["value"];

    The great thing is I can even define whatever attribute I want right
    inside the html

    <asp:checkbox id="cbxTest" runat=server value="whatever" />

    , Adam


    "Thomas Nielsen [AM Production A/S]" <> wrote in message news:<>...
    > I've been struggling (for too much) with checkboxes in repeaters. It's a
    > mystery to me why the <asp:checkbox> control does not expose a value
    > property for the checkbox, so that you would be able to identify the
    > checkbox on postback.
    >
    > Can anyone comment on best practices for working with checkboxes inside
    > repeaters?.
    >
    > Thanks,
    >
    > Thomas
    Adam, Dec 11, 2003
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fresh Air Rider

    Checkboxes with Repeaters and DataGrids

    Fresh Air Rider, Mar 5, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    488
    Fresh Air Rider
    Mar 5, 2004
  2. =?Utf-8?B?TWFjaGk=?=

    nested Repeaters with javascript checkboxes

    =?Utf-8?B?TWFjaGk=?=, Apr 16, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    530
    =?Utf-8?B?TWFjaGk=?=
    Apr 16, 2004
  3. Fresh Air Rider

    Checkboxes with Repeaters and DataGrids

    Fresh Air Rider, Mar 5, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    145
    Fresh Air Rider
    Mar 5, 2004
  4. Fresh Air Rider

    Checkboxes with Repeaters and DataGrids

    Fresh Air Rider, Mar 5, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    128
    Fresh Air Rider
    Mar 5, 2004
  5. oldyork90
    Replies:
    1
    Views:
    157
    Jeremy J Starcher
    Sep 10, 2008
Loading...

Share This Page