Cannot set ListItem Value

Posted on 2006-05-18
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?

    LVL 17

    Assisted Solution

    can you post the entrie code of the method where is the code subbmited?
    LVL 11

    Accepted Solution

    Try this:
    _list.Items.FindByValue("test").Selected = true;
    LVL 6

    Author Comment

    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.

    LVL 6

    Author Comment

    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

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now