473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Checkbox list

Hi all,
Good Day

am working on asp.net 2.0, c#

i stored checkbox list selected values separating with . as
Expand|Select|Wrap|Line Numbers
  1. string s = null;
  2.          for (int i = 0; i < chlistDomains.Items.Count; i++)
  3.          {
  4.              if (chlistDomains.Items[i].Selected)
  5.              {
  6.                  s = s + chlistDomains.Items[i].Value + ".";
  7.              }
  8.          }
  9.  
i retrieved that value in to a string variable

now am trying to selectcheckbox list values which are in that string variable
i wrote following code but it is selecting last value only
Expand|Select|Wrap|Line Numbers
  1. string[] sp1 = pref.Split('.');
  2.             for (int j = 0; j < sp1.Length; j++)
  3.             {
  4.                 clistPrefferedEmployement.SelectedValue = Convert.ToString(sp1[j]);
  5.             }
please suggest me

Thanks in advance
Oct 6 '08 #1
4 1071
snester
12
The .SelectedValue method will only select a single value..

you should select each item specifically:

Also, you could use an array to capture your values:

Expand|Select|Wrap|Line Numbers
  1. string[] s = new string(chlistDomains.Items.Count());
  2.  
  3.         for (int i = 0; i < chlistDomains.Items.Count; i++)
  4.         {
  5.             if (chlistDomains.Items[i].Selected)
  6.             {
  7.                 s[i] = chlistDomains.Items[i].Value;
  8.             }
  9.         }
  10.  
  11.         foreach (string item in s)
  12.         {
  13.             clistPrefferedEmployement.Items[theitemhere].Value = item;
  14.         }
  15.  
Hope this helps?
Oct 6 '08 #2
Expand|Select|Wrap|Line Numbers
  1. foreach (string item in s)
  2. {
  3. clistPrefferedEmployement.Items[theitemhere].Value = item;
  4. }
  5.  
in this stmt wt was theitemhere?

The .SelectedValue method will only select a single value..

you should select each item specifically:

Also, you could use an array to capture your values:

string[] s = new string(chlistDomains.Items.Count());

for (int i = 0; i < chlistDomains.Items.Count; i++)
{
if (chlistDomains.Items[i].Selected)
{
s[i] = chlistDomains.Items[i].Value;
}
}

foreach (string item in s)
{
clistPrefferedEmployement.Items[theitemhere].Value = item;
}

Hope this helps?
Oct 6 '08 #3
snester
12
I'm sorry, my code was slightly incorrect before, hopefully this should be self explainitory..

Expand|Select|Wrap|Line Numbers
  1. int count = 0;
  2.             int[] n = new int[chlistDomains.Items.Count];
  3.             int trackPos = 0;
  4.             string[] s = new string[chlistDomains.Items.Count];
  5.  
  6.             for (int i = 0; i < chlistDomains.Items.Count; i++)
  7.             {
  8.                 if (chlistDomains.Items[i].Selected)
  9.                 {
  10.                     count++;
  11.                     n[i] = trackPos;
  12.                     s[i] = chlistDomains.Items[i].Value;
  13.                 }
  14.                 trackPos++;
  15.             }
  16.  
  17.  
  18.             int listPos = 0;
  19.             foreach (string item in s)
  20.             {
  21.                 if (clistPrefferedEmployement.Items[n[listPos]].Value == item)
  22.                 {
  23.                     clistPrefferedEmployement.Items[n[listPos]].Selected = true;
  24.                 }
  25.                 listPos++;
  26.             }
I have made assumptions based on your original post, I hope they are correct:
- the items in chlistDomains and clistPrefferedEmployement are the same and in the same order.
- the items are already in the clistPrefferedEmployement list prior to the event.

(if not, you could always add the items into clistPrefferedEmployement) just replace the foreach statement with:

Expand|Select|Wrap|Line Numbers
  1.             int listPos = 0;
  2.             foreach (string item in s)
  3.             {
  4.                 clistPrefferedEmployement.Items.Add(item);
  5.             }
Hope this is clearer than my first answer?
Oct 6 '08 #4
Curtis Rutland
3,256 Expert 2GB
Both of you need to start using code tags when you post. snester, you're new to the site, so there is some excuse, but Vajrala Narendra, you have over 50 posts. You should know this by now. I see you were trying to use [b] tags. This is for bold text. [code] is what you need to use for code.

Code tags are not optional, they are required. Please start using them.

MODERATOR
Oct 6 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Rodney King | last post by:
Hi, I have developed an ASP page which dynamically displays a list of checkbox options based on a SQL statement. Here is my code: <div style="OVERFLOW:auto; Height: 150px"> <table> <% dim...
4
by: feanor | last post by:
I need to select children checkboxes when selecting the parent one. This is my function: function SelectChildrens(checkbox_name){ form = document.forms; Sname = checkbox_name.split("-"); for...
0
by: Steven | last post by:
Hi, I'm creating a custom checkbox list control which will take 2 arraylists as input. (One will contain Names and other will contain 0s and 1s. 0 - uncheck 1- check). I'm able to create the...
2
by: Martin | last post by:
Hi, Please can somebody explain how databinding is done on a checkbox list. I have the follwoing code which I would have thought was enough to databind a checkbox, but apparently not. The...
8
by: Alan Silver | last post by:
Hello, I have a repeater that has code like this... <ItemTemplate> <asp:CheckBox ID="chkDelete" Text="" RunAt="server"/> .... other stuff goes here </ItemTemplate> There is a button below...
6
by: Daz | last post by:
Hi everyone. Firstly, I apologise if this i not what you would call a PHP problem. I get quite confused as to what lives in which realm, so if this shouldn't be posted here, please suggest where...
1
by: snsit1 | last post by:
Hello - i am wondering if anyone can help, I am fairly new to javascript / html and am having difficulty getting selected options ticked using check boxes out to a .txt file and have another script...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
3
by: uremog | last post by:
I have a set of of check boxes. onClick, the checkboxes call check_radio and recup_checkbox. the referenced radios function as group selectors. check_radio just unchecks the radios if someone...
2
markrawlingson
by: markrawlingson | last post by:
Hi guys, I have a bunch of drop down lists on a page, with a checkbox beside each one that relates to each one respectively. When a user selects an option from the drop down, the checkbox is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.