Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Bind Array to SelectedIndex of Checkboxlist?

Reply
Thread Tools

Bind Array to SelectedIndex of Checkboxlist?

 
 
=?Utf-8?B?VG9t?=
Guest
Posts: n/a
 
      05-04-2004
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?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
Guest
Posts: n/a
 
      05-04-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
confused by boost::bind & boost::lambda::bind XHengDF@gmail.com C++ 0 05-29-2007 04:37 AM
Using a data-bind dropdownlist to populate another data-bind dropdownlist mr2_93 ASP .Net 1 10-02-2005 05:07 PM
Bind Array to SelectedIndex of Checkboxlist? Tom ASP .Net Web Controls 0 05-03-2004 07:31 PM
should I bind datagrid to array or temporary dataset? AFN ASP .Net 3 02-16-2004 08:50 PM
How to bind a db image column (byte array) to a datagrid column? Jim Hammond ASP .Net 1 11-26-2003 12:55 AM



Advertisments