Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 601195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:41:17+00:00 2026-05-13T16:41:17+00:00

I have a simple usercontrol, with a datalist, and checkboxes inside. <asp:DataList ID=DataListDroits runat=server

  • 0

I have a simple usercontrol, with a datalist, and checkboxes inside.

 <asp:DataList ID="DataListDroits" runat="server" DataKeyField="droit_id" DataSourceID="SqlDroits">
      <ItemTemplate>
           <asp:HiddenField ID="HiddenFieldDroitID" runat="server" Value='<%# Eval("droit_id") %>' />
           <asp:CheckBox ID="CheckBoxDroit" runat="server" Text='<%# Eval("droit_label") %>' />
      </ItemTemplate>
 </asp:DataList>

I check them using code behind in the usercontrol :

 Public Sub CheckRole(ByVal role As Integer)
     For Each dliOrganisme As DataListItem In Me.DataListOrganismes.Items
         Dim DataListDroits As DataList = dliOrganisme.FindControl("DataListDroits")
         If DataListDroits IsNot Nothing Then
             For Each dliDroit As DataListItem In DataListDroits.Items
                 If role = CInt(CType(dliDroit.FindControl("HiddenFieldDroitID"), HiddenField).Value) Then
                     Dim CheckBoxDroit As CheckBox = dliDroit.FindControl("CheckBoxDroit")
                     CheckBoxDroit.Checked = True
                 End If
             Next ' DataListDroits
         End If
     Next ' DataListItem
 End Sub

And in the page_load of the calling webform :

            Dim CheckBoxesRoles1 As ASP.organisme_checkboxesroles_ascx = Me.FormViewRubrique.FindControl("CheckBoxesRoles1")
            Dim rolesCoches As New List(Of Integer)
            Dim cmdRoles As New SqlCommand("SELECT droit_id FROM o_droit_rubrique WHERE rubrique_id = @rubrique", conn)
            cmdRoles.Parameters.AddWithValue("rubrique", Request.QueryString("rid"))
            Dim rdrRoles As SqlDataReader = cmdRoles.ExecuteReader
            While rdrRoles.Read
                CheckBoxesRoles1.CheckRole(rdrRoles("droit_id"))
            End While
            rdrRoles.Close()

… and yet, they are not checked.
But if I do this :

 Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
    Dim CheckBoxesRoles1 As ASP.organisme_checkboxesroles_ascx = Me.FormViewRubrique.FindControl("CheckBoxesRoles1")
    If CheckBoxesRoles1 IsNot Nothing Then
        For Each role As Integer In CheckBoxesRoles1.CheckedRoles
            Response.Write("role : " & role & "<br>")
        Next
    End If
 End Sub

I tells me they are…

I’m going mad here ! Why does it tells me they are checked while they obviously are not ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:41:18+00:00Added an answer on May 13, 2026 at 4:41 pm

    Well… for one thing, you aren’t checking if your checkboxes are checked, all you’re doing is outputting the value of “role”. What exactly are you expecting here?

    Two suggestions:
    1) Set the Checked property of your CheckBox in the aspx like so:

    <asp:CheckBox ID="CheckBoxDroit" runat="server"  Text='<%# Eval("droit_label") %>' Checked='<%# (Eval("droit_id") > 0).ToString()' />
    

    2) Set the property in OnItemDataBound in code-behind

    One of two things is happening: Either the code you expect to be executing is not really executing (ie, is your if block ever true? Is the control not being found? Try a breakpoint), OR you are doing it at the wrong time — after the page has already been rendered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple UserControl whose direct Child element is a border:- <Border x:Name=LayoutRoot
I have the following simple code: <Window x:Class=WpfApplication3.MainWindow x:Name=WindowInst …> <local:UserControl1/> </Window> <UserControl x:Class=WpfApplication3.UserControl1
I have some userControl that contain simple button. I want to bind the button
I have a simple user control which wraps some logic around an AutoCompleteBox. This
I have a simple application with just a window and a user control. The
I have built a simple shopping cart. The problem is that the first time
I have built a Wpf UserControl Library and it contains a large group of
I have been searching all over the web trying to find an example of
Im having some problems with databinding inside a DataTemplate. In the ControlTemplate below the
I am basically using a user control for the first time, so hopefully it's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.