ListBox Not Functioning.....Multiple Selection
-
I am doing an application in ASP .NET in which i am using a list box with multiple selection. I am using a sqldatasource to bind values to the list box. Everything works fine till this. i want the page to send the selected multiple values in list box to be in two different text boxes i tried this code and working, all the selected values comes to single text boxes. I want first selected value to be in textbox1 and second value to be in textbox2.. This is the code... On Click event of a button
int i; txt\_uname1.Text = "selected" + " "; for (i = 0; i < list\_users.Items.Count - 1; i++) { if (list\_users.Items\[i\].Selected) { //txt\_uname1.Text = list\_users.Items\[i\].Text; txt\_uname1.Text = txt\_uname1.Text + list\_users.Items\[i\].Text + " "; } }
Please help me fixing this... Thanks in advance
SAJAN A PILLAI ASP.NET,C#.NET Programmer BANGALORE "Winners don't do different things. They do things differently. ...
-
I am doing an application in ASP .NET in which i am using a list box with multiple selection. I am using a sqldatasource to bind values to the list box. Everything works fine till this. i want the page to send the selected multiple values in list box to be in two different text boxes i tried this code and working, all the selected values comes to single text boxes. I want first selected value to be in textbox1 and second value to be in textbox2.. This is the code... On Click event of a button
int i; txt\_uname1.Text = "selected" + " "; for (i = 0; i < list\_users.Items.Count - 1; i++) { if (list\_users.Items\[i\].Selected) { //txt\_uname1.Text = list\_users.Items\[i\].Text; txt\_uname1.Text = txt\_uname1.Text + list\_users.Items\[i\].Text + " "; } }
Please help me fixing this... Thanks in advance
SAJAN A PILLAI ASP.NET,C#.NET Programmer BANGALORE "Winners don't do different things. They do things differently. ...
What if user selects more than 3 items from the ListBox ? Where are you going to show those items ? Code modification for your logic (Not tested) int i; txt_uname1.Text = "selected" + " "; bool isFirstSelected for (i = 0; i < list_users.Items.Count - 1; i++) { if (list_users.Items[i].Selected) { if(!isFirstSelected) { //TextBox 1 txt_uname1.Text = list_users.Items[i].Text; isFirstSelected=true; } else { //Text Box 2 txt_uname2.Text = list_users.Items[i].Text; break; } }
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog
-
I am doing an application in ASP .NET in which i am using a list box with multiple selection. I am using a sqldatasource to bind values to the list box. Everything works fine till this. i want the page to send the selected multiple values in list box to be in two different text boxes i tried this code and working, all the selected values comes to single text boxes. I want first selected value to be in textbox1 and second value to be in textbox2.. This is the code... On Click event of a button
int i; txt\_uname1.Text = "selected" + " "; for (i = 0; i < list\_users.Items.Count - 1; i++) { if (list\_users.Items\[i\].Selected) { //txt\_uname1.Text = list\_users.Items\[i\].Text; txt\_uname1.Text = txt\_uname1.Text + list\_users.Items\[i\].Text + " "; } }
Please help me fixing this... Thanks in advance
SAJAN A PILLAI ASP.NET,C#.NET Programmer BANGALORE "Winners don't do different things. They do things differently. ...
For that instead of assigning values directly to textbox,first you store values to a string array.And after that you create other loop and assign values to your textboxes. Hope this will help you
-
What if user selects more than 3 items from the ListBox ? Where are you going to show those items ? Code modification for your logic (Not tested) int i; txt_uname1.Text = "selected" + " "; bool isFirstSelected for (i = 0; i < list_users.Items.Count - 1; i++) { if (list_users.Items[i].Selected) { if(!isFirstSelected) { //TextBox 1 txt_uname1.Text = list_users.Items[i].Text; isFirstSelected=true; } else { //Text Box 2 txt_uname2.Text = list_users.Items[i].Text; break; } }
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog
Thanks for the reply....It works.
SAJAN A PILLAI ASP.NET,C#.NET Programmer BANGALORE "Winners don't do different things. They do things differently. ...