Bind Array to SelectedIndex of Checkboxlist?

G

Guest

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?
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top