Bind Array to SelectedIndex of Checkboxlist?

Discussion in 'ASP .Net' started by =?Utf-8?B?VG9t?=, May 4, 2004.

  1. Hi

    There are a Checkboxlist with 20 checkboxitems and a string "1,3,5,7,9,11,13,15,17,20" which are those selectedindex of the checkboxlist. I used a foreach looping to record those selectedindex and I split the string and put them to a string array.

    However, how can I assign those string array to SelectedIndex of Checkboxlist

    [code
    C#
    protected System.Web.UI.WebControls.CheckBoxList c
    string a = "1,3,5,7,9,11,13,15,17,20"
    string[] b = a.Split(',')
    for(int k=0; k < this.c.Items.Count; k++

    if(this.c.Items[k].Value == b[k]

    this.c.SelectedIndex = k


    [/code

    I used databind to bind a table to the checkboxlist

    this.c.DataSource = ds.Tables[0].DefaultView
    this.c.DataTextField = "checkboxitemname"
    this.c.DataValueField = "id"
    this.c.DataBind()

    This code only shows the 20th selectedindex of the 20 checkboxlistitems. 1,3,5,7,9,11,13,15,17 were not selected

    SelectedIndex does not has array. How can I fix this problem?
    =?Utf-8?B?VG9t?=, May 4, 2004
    #1
    1. Advertising

  2. Hi, To

    Use Selected = true instead of SelectedIndex

    protected System.Web.UI.WebControls.CheckBoxList c
    string a = "1,3,5,7,9,11,13,15,17,20"
    string[] b = a.Split(',')
    for(int k=0; k < this.c.Items.Count; k++

    if(this.c.Items[k].Value == b[k]

    this.c.Items[k].Selected = true



    Bin Song MCP
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, May 4, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JD
    Replies:
    5
    Views:
    11,615
    NetArchitect
    Aug 8, 2007
  2. Patrick.O.Ige
    Replies:
    5
    Views:
    19,071
    Patrick.O.Ige
    Jun 19, 2005
  3. Larry R

    Bind CheckBoxList to Business Object

    Larry R, May 19, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    487
    Larry R
    May 20, 2006
  4. Replies:
    0
    Views:
    509
  5. Tom

    Bind Array to SelectedIndex of Checkboxlist?

    Tom, May 3, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    129
Loading...

Share This Page