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 DataList like below: <asp:DataList runat=server ID=myDataList> <ItemTemplate> <uc:MyControl ID=id1 runat=server PublicProperty='<%#
I have a custom UserControl which uses a simple ITemplate: <asp:Panel runat=server ID=pnlExpander CssClass=expander>
I have a partial view (UserControl) that implements a simple pager in my Asp.Net
I have an HtmlGenericControl which is a simple DIV with runat=server This Control is
I have asp.net usercontrol and I should implement simple client functionality - send two
I have this simple UserControl : <UserControl x:Class=WPFTreeViewEditing.UserControl1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006 xmlns:d=http://schemas.microsoft.com/expression/blend/2008 mc:Ignorable=d d:DesignHeight=300
I have a simple UserControl for database paging, that uses a controller to perform
I have a simple UserControl containing a ComboBox which is empty at first. The
All, I have a simple class. public class Container : UserControl { public bool
i have a simple usercontrol with following properties: public partial class RichTextEditorControl : UserControl

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.