Home All Groups Group Topic Archive Search About

Getting Value out of a data repeater checkbox

Author
15 Dec 2005 6:23 PM
jim.long
I can't seem to get the checked value from the checkboxes! Is there
something wrong with the code? It loops through the repeater item
collection correctly.
HTML:
<asp:repeater id="rPrinterJobs" runat="server">
     <ItemTemplate>
          <tr>
    <td><asp:CheckBox ID="chkboxSelection"  Checked=true Runat="server"
Enabled="true"></asp:CheckBox>
    <asp:Label ID="hdnStoreID" Visible="false" Text='<%#
DataBinder.Eval(Container.DataItem, "UColumn0") %>'
Runat=server></asp:Label>
    </td>
          </tr>
     </ItemTemplate>
</asp:repeater>

Code Behind:
        Dim DataItem As RepeaterItem
        Dim chkSelected As System.Web.UI.WebControls.CheckBox
        Dim strJobID As String

        Dim rc As RepeaterItemCollection = rPrinterJobs.Items
        Dim MyCheckBox As CheckBox

        For Each Item As RepeaterItem In rc
            MyCheckBox = CType(Item.FindControl("chkboxSelection"),
CheckBox)
            If MyCheckBox.Checked = True Then
                strJobID = CType(Item.FindControl("hdnStoreID"),
Label).Text
                If strJobID > "" Then
                     'Do something
                End If
            End If
        Next

Author
15 Dec 2005 7:03 PM
Karl Seguin
Looks right.

Wha'ts not working?  Is MyCheckBox.Checked always false? Are you getting
past that but strJobID is empty?

Where's this code?  In a button event handler?  Is viewstate on?

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/


<jim.l***@vanderbilt.edu> wrote in message
Show quoteHide quote
news:1134670998.704467.140760@g44g2000cwa.googlegroups.com...
>I can't seem to get the checked value from the checkboxes! Is there
> something wrong with the code? It loops through the repeater item
> collection correctly.
> HTML:
> <asp:repeater id="rPrinterJobs" runat="server">
>     <ItemTemplate>
>          <tr>
> <td><asp:CheckBox ID="chkboxSelection"  Checked=true Runat="server"
> Enabled="true"></asp:CheckBox>
> <asp:Label ID="hdnStoreID" Visible="false" Text='<%#
> DataBinder.Eval(Container.DataItem, "UColumn0") %>'
> Runat=server></asp:Label>
> </td>
>          </tr>
>     </ItemTemplate>
> </asp:repeater>
>
> Code Behind:
>        Dim DataItem As RepeaterItem
>        Dim chkSelected As System.Web.UI.WebControls.CheckBox
>        Dim strJobID As String
>
>        Dim rc As RepeaterItemCollection = rPrinterJobs.Items
>        Dim MyCheckBox As CheckBox
>
>        For Each Item As RepeaterItem In rc
>            MyCheckBox = CType(Item.FindControl("chkboxSelection"),
> CheckBox)
>            If MyCheckBox.Checked = True Then
>                strJobID = CType(Item.FindControl("hdnStoreID"),
> Label).Text
>                If strJobID > "" Then
>                     'Do something
>                End If
>            End If
>        Next
>
Are all your drivers up to date? click for free checkup

Author
15 Dec 2005 7:09 PM
jim.long
MyCheckBox.Checked is always false. Yes it is in a button event handler.
Author
15 Dec 2005 7:23 PM
Karl Seguin
Something doesn't seem right.  are you rebinding the repeater on postback or
is it wrapped in an if not page.ispostback ?



--
MY ASP.Net tutorials
http://www.openmymind.net/


<jim.l***@vanderbilt.edu> wrote in message
Show quoteHide quote
news:1134673764.510774.250970@f14g2000cwb.googlegroups.com...
> MyCheckBox.Checked is always false. Yes it is in a button event handler.
>
Author
15 Dec 2005 7:30 PM
jim.long
THe if not page.ispostback was the problem! Thanks for thinking of it!

Bookmark and Share