Checkbox list in ComboBox Not persisting checks

Not Answered This post has 0 verified answers and 11 replies

Top 50 Contributor
Posts: 103
ladams Posted: Mon Feb 1, 2010 @ 6:59 AM
I have a asp.net checkbox list inside a combobox's DropDownContent.  When setting the checkbox list's selected items on the server they do not persist when rendered.  I took the list out of the combobox and everything worked fine.

Suggestions?

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ecfRoleList.ascx.cs"
    Inherits="USCourts.AttorneyReg.Admin.Web.controls.ecfRoleList" %>
<%@ Register Assembly="ComponentArt.Web.UI" Namespace="ComponentArt.Web.UI" TagPrefix="CA" %>
<CA:ComboBox runat="server" ID="comboRoles" AutoHighlight="false" AutoComplete="false"
    Text="Select ECF Groups" DropImageUrl="App_Themes/default/images/ddn.png" Width="175"
    ItemCssClass="ddn-item" ItemHoverCssClass="ddn-item-hover" CssClass="cmb" HoverCssClass="cmb-hover"
    TextBoxCssClass="txt" DropDownWidth="225" DropDownHeight="300" DropDownCssClass="ddn" EnableViewState="true"
    DropDownContentCssClass="ddn-con">
    <DropDownContent>
        <asp:CheckBoxList runat="server" ID="chkRoles" Font-Bold="true" RepeatColumns="1" RepeatDirection="Vertical"></asp:CheckBoxList>
    </DropDownContent>
</CA:ComboBox>

All Replies

Top 10 Contributor
Posts: 2,373
harish Posted: Mon Feb 1, 2010 @ 7:22 AM

Hello,

 

Thank you for submitting your query with ComponentArt Forum.

 

Please see the attached sample project in which the checkbox list's selected item persist when rendered. I have checked this sample using ComponentArt version 2009.3.1762.35.

 

Thanks.

 

Harish Malhotra

Top 50 Contributor
Posts: 103
ladams Posted: Mon Feb 1, 2010 @ 7:44 AM
First of all your example does not work as there is no checkboxList control on the page.  Also, I am not attempting to use the SelectedIndex.  A checkboxList SelectedIndex is defined as:

The lowest ordinal index of the selected items in the list. The default is -1, which indicates that nothing is selected.....

I am looping the checkboxList's item collection and setting their listItem .checked = true;

Such As:
 public void SetSelectedGroups(List<string> GroupNames) {
            foreach (var g in GroupNames) {
                ListItem l = chkRoles.Items.FindByText(g);
                if (l != null)
                    l.Selected = true;
            }
        }

One thing to note is this is in a UserControl.

When stepping through the code everything is correctly persisted all the way through PreRender.  But not rendered correctly.

Again, when I remove the checkboxList from the combobox everything works fine.  Only when in the combobox does my checkbox list items not persist correctly on render.



Top 10 Contributor
Posts: 2,373
harish Posted: Mon Feb 1, 2010 @ 8:07 AM

Hello,

 

Please accept my apologies for the incorrect sample. I have attached the modified sample which now has the combo inside the Webusercontrol. I have explicitly set the item with text "third" as selected on button click.

 

Hope it helps.

 

Thanks.

 

Harish Malhotra

Top 50 Contributor
Posts: 103
ladams Posted: Mon Feb 1, 2010 @ 8:55 AM
This appears to be a databinding issue.  I was binding my list like this:
GroupController groupData = new GroupController(SiteSettings.Instance.ConnectionString, "IBM.Data.Informix");
            var groups = groupData.GetGroups();
            groups.RemoveAll(a => a.Name.StartsWith("reserved"));
            chkRoles.DataSource = groups;
            chkRoles.DataTextField = "Name";
            chkRoles.DataBind();
Which fails to allow checking items after binding.


When I manually create my listItems like:

public void LoadGroups() {
            GroupController groupData = new GroupController(SiteSettings.Instance.ConnectionString, "IBM.Data.Informix");
            var groups = groupData.GetGroups();
            groups.RemoveAll(a => a.Name.StartsWith("reserved"));

            foreach (var g in groups) {
                chkRoles.Items.Add(new ListItem() { Text = g.Name });
            }
        }
It works...

I believe there is a bug somewhere in the comboBox because again binding either way works when not nested in a ComboBox.

Top 10 Contributor
Posts: 2,373
harish Posted: Mon Feb 1, 2010 @ 10:01 AM

Hello,

 

Thanks for getting back to me.

 

It seems when you are binding to collection then you are facing the rendering issue. In order to replicate the same I have modified the sample project in which I have bound with a simple collection of datatable and observed the rendering is working fine when I use either of the two approaches which you have mentioned.

 

Thanks.

 

Harish Malhotra

Not Ranked
Posts: 2
CBCIT Posted: Sun Apr 29, 2012 @ 4:34 AM
Hello harish,
If i have to update the checkbox list view combobox callback (AutocompleteTrue, renderMode=callback) 
How do I do that? 
Not Ranked
Posts: 2
CBCIT Posted: Sun Apr 29, 2012 @ 4:42 AM
sorry,
I've ment "runningMode=Callback" 
Top 200 Contributor
Posts: 33
arjunroy Posted: Wed Aug 22, 2012 @ 2:12 PM
Hello,

I am having some issue persisting checks of the checkboxlist which is inside a combobox.

My case is little bit different from the one you have proposed in nesting_content_modified.zip in that I would like a bunch of checkboxes to be checked when the user clicks Set Index button.

To do so, I modified your code as follows:

In WebUserControl.ascx
protected void Button2_Click(object sender, EventArgs e)
    {
        // I want to check the checkboxes 2nd and 3rd
        ListItem l;
        for (int i = 2; i < 4; i++)
        {
            l = chkRoles.Items.FindByValue(i.ToString());
            if (l != null)
                l.Selected = true;
        }
    }

In WebUserControl.ascx.cs
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("value", typeof(double));
            dt.Rows.Add(new object[] { "Jan", 1 });
            dt.Rows.Add(new object[] { "Feb", 2 });
            dt.Rows.Add(new object[] { "Mar", 3 });
            dt.Rows.Add(new object[] { "Apr", 4 });
            dt.Rows.Add(new object[] { "May", 5 });
            dt.Rows.Add(new object[] { "Jun", 6 });

            chkRoles.DataSource = dt;
            chkRoles.DataTextField = "Name";
            chkRoles.DataBind();
        }

For some reason, in this case the two checkboxes do not persist.
Any opinion/feedback is really appreciated.

Thanks



Top 10 Contributor
Posts: 2,373
harish Posted: Thu Aug 23, 2012 @ 5:23 AM
Hello,
 
I have gone through the code provided by and tried to replicate the issue using the latest build version 2012.1.1016.4 using your code. Further, I have modified the SetIndex Button click code and observed I am able to check a bunch of checkboxes when clicked on the SetIndex button. The code sinppet is as follows:
 

protected void Button2_Click(object sender, EventArgs e)

    {

        ListItem l ;

        for (int i = 2; i < 4; i++)

        {

            l = chkRoles.Items[i];

            if (l != null)

            l.Selected = true;

        } 

    }

 
Also I have attached the sample for your reference which exhibits the same.
 
Hope it helps you.
 
Thank you.
Harish Malhotra    
Top 200 Contributor
Posts: 33
arjunroy Posted: Thu Aug 23, 2012 @ 1:32 PM
Thank you!

Top 10 Contributor
Posts: 2,373
harish Posted: Fri Aug 24, 2012 @ 3:07 AM

Thanks for posting.

 

Harish Malhotra

Page 1 of 1 (12 items)