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 8951753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:44:11+00:00 2026-06-15T13:44:11+00:00

I get the feeling I’m missing something really basic about the asp.net page life

  • 0

I get the feeling I’m missing something really basic about the asp.net page life cycle here.

I have a CheckBoxList (Although the same thing happens with a ListBox)

    <asp:CheckBoxList runat="server" ID="cblCountriesAccessible" DataTextField="Text" />

I’m adding a bunch of ListItems to it

        var lbData = new List<ListItem>();
        lbData.Add(new ListItem("x", "", true));
        lbData.Add(new ListItem("y", "", false));

Then Binding them to the CheckBoxList

    cblCountriesAccessible.DataSource = lbData;
    cblCountriesAccessible.DataBind();

And every time the items in the list show up at unchecked (or unselected in a ListBox)
If I add the ListItems directly to the control in the markup, they show up just fine as selected or unselected.

    <asp:ListItem Text="x" Value="" Selected="True" />

What am I doing wrong in the code that selected doesn’t carry through? I’ve tried binding CheckBoxes in with Checked set to true, and the same thing happens.

Edit: OK, I wasn’t setting Selected correctly. I’m now using

        var lbData = new List<ListItem>();
        var l1 = new ListItem("yy", "", true) {Selected = true};
        var l2 = new ListItem("xx", "", true) {Selected = false};

        lbData.Add(l1);
        lbData.Add(l2);

And they’re still not loading as checked

  • 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-06-15T13:44:12+00:00Added an answer on June 15, 2026 at 1:44 pm

    You can create ListItem change its Selected property and add in collection.

    ListItem li1 = new ListItem("x", "", true);
    ListItem li2 = new ListItem("x", "", true); 
    li1.Selected = true; 
    li2.Selected = true;
    cblCountriesAccessible.Items.Add(li1);
    cblCountriesAccessible.Items.Add(li2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the feeling I'm missing something obvious, but I'm new to all of
I get the feeling this is probably something I should know but I can't
I get the feeling I am still using asp type scripting techniques in the
In my application, I have the following recurring pattern where I get the feeling
I have tried to deploy a WebORB .NET C# ASP.NET (C#.NET) application, but I
I tend to get the feeling that most folks here think SVN is gold-plated
After researching various hosts, I still get the feeling that it is somewhat impossible
I wish to get a quick feeling for how much copy and paste coding
I get the feeling almost everybody uses an editor (Vim, Notepad++, etc.) for the
I feel like this deserves a good comment but I get the feeling that

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.