By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,326 Members | 2,726 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,326 IT Pros & Developers. It's quick & easy.

Bind Array to SelectedIndex of Checkboxlist?

P: n/a
Tom
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?
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.