[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Cannot set ListItem Value

Posted on 2006-05-18
Medium Priority
Last Modified: 2008-03-10
If I have the following simple codebehind:

CheckBoxList _list = new CheckBoxList();
_list.Items.Add(new ListItem("test", "test"));

It will not set the value for the listitem in the checkboxlist.
Does anyone know why or how to fix it?

Question by:Brian Bush
  • 2
LVL 18

Assisted Solution

by:Elvio Lujan
Elvio Lujan earned 400 total points
ID: 16710678
can you post the entrie code of the method where is the code subbmited?
LVL 11

Accepted Solution

TornadoV earned 1600 total points
ID: 16710716
Try this:
_list.Items.FindByValue("test").Selected = true;

Author Comment

by:Brian Bush
ID: 16710902
What I am saying is that the ListItem should generate a
value="test" property in the HTML at runtime and it does not.

So, when the form is submitted all I can get is the value "on"
that I can associate with a field ID that it generates based
on the listcontrol id and an index. That's useless.

I found some documentation about it. I would like a workaround
that is less intensive than extending a control class.



Author Comment

by:Brian Bush
ID: 16710970
I wrote a Javascript function to set the values onsubmit.
Dear Microsoft, This is lame!

function SetCheckValues(CheckBoxListID) {
      var _list = document.getElementById(CheckBoxListID);
      var _chks = _list.getElementsByTagName('INPUT');
      var _lbls = _list.getElementsByTagName('LABEL');

      for (_i = 0; _i < _chks.length; _i++) {
            _chks[_i].value = _lbls[_i].innerText;

I am closing this case but splitting the points so it won't get deleted.
Surely someone else has seen this issue.

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question