I try the foll. code---
protected void Button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i <= ListBox1.Items.Count - 1; i++)
{
ListBox1.Items.Remove(ListBox1.SelectedValue.ToStr ing());
}
}
But it's not working.
7 6149
If your wanting to remove all the items with this loop you need to replace - ListBox1.Items.Remove(ListBox1.SelectedValue.ToString());
with - ListBox1.Items.Remove(ListBox1.Items[i]);
If your only wanting to replace the selected items you need to replace - for (i = 0; i <= ListBox1.Items.Count - 1; i++)
with - for (i = 0; i <= ListBox1.SelectedItems.Count - 1; i++)
and - ListBox1.Items.Remove(ListBox1.SelectedValue.ToString());
with - ListBox1.Items.Remove(ListBox1.SelectedItems[i]);
I try the foll. code---
protected void Button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i <= ListBox1.Items.Count - 1; i++)
{
ListBox1.Items.Remove(ListBox1.SelectedValue.ToStr ing());
}
}
But it's not working.
Hi to remove all the items--
listbox1.items.clear();
Code given by you to remove selected Items is not working.
Are you trying to delete the selected items? If so, check out the SelectedItems property.
Also, since you are deleting on each iteration, you cannot go forward, since deleting from the front makes all the items indeces decrease. To fix that, either iterate for the number of items, deleting the 0th element on each iteration, or else start from the back and decrement, each time deleting the ith element.
You also might want to use the foreach loop, as it implicitly iterates until the collection is out of elements. -
foreach(object Item in listBox1.SelectedItems)
-
{
-
this.listBox1.Items.Remove(Item);
-
}
-
-
hey frnds, there is no SelectedItems Property in ASP.Net, y al u r replying SelectedItems Property,IN ASP there is either SelectedItem ya SelectedValue Property.
hey frnds, there is no SelectedItems Property in ASP.Net, y al u r replying SelectedItems Property,IN ASP there is either SelectedItem ya SelectedValue Property.
Oh, I'm sorry. I forgot that this was ASP. Try: -
while (this.ListBox1.SelectedItem != null )
-
{
-
this.ListBox1.Items.Remove(this.ListBox1.SelectedItem);
-
}
-
Hi Sonia,
Tell exact requirement of your project... if u want to move all the items of listbox then use following code which will allows u to move all the items from one list box to another.. and by editing this code u can also just removes the items of particular listbox.... -
if(id=="ctl00_ContentPlaceHolder1_TabAddCompany_TabPanel1_btnnextall")
-
{
-
if(lstavailablestate.length < 1)
-
{
-
alert('There are no items in the source ListBox');
-
return false;
-
}
-
var i = 0;
-
for (i = 0; i <= lstavailablestate.length -1 ; i++)
-
{
-
var len = lstassociatedstate.length++;
-
lstassociatedstate.options[len].text = lstavailablestate.options[i].text;
-
lstassociatedstate.options[len].value = lstavailablestate.options[i].value;
-
hid = hid + lstavailablestate.options[i].value + ",";
-
}
-
for(var i=(lstavailablestate.options.length-1); i>=0; i--)
-
{
-
lstavailablestate.options[i] = null;
-
}
-
-
}
-
And ya i have write the code at client side that is in javascript....
Sign in to post your reply or Sign up for a free account.
Similar topics
by: theoryboy |
last post by:
I'm trying to implement multiple selection functionality in a Tix Hlist
using a control-click. I've bound control-click to a function that uses
selection_set to add to the selection, but it doesn't...
|
by: Graham Swindon |
last post by:
What is the best way to delete multiple records selected from a list box?
|
by: ted |
last post by:
Hi,
I can't figure out how to set multiple items in a ListBox to selected when
the listbox is in a User Control.
When the ListBox is set in directly into a form I can use the following:...
|
by: bill yeager |
last post by:
Duray, it helps in regards to knowing how to get the items
that were selected in the lisbox, but I'm going in
reverse --- after I get the items from the db that were
selected, I'd like to be able...
|
by: Peter |
last post by:
Hello!
Please, could anyone tell, is it possible to set multiple items to be
selected in list control in the code? For example when the web form is loaded
three items of 5 are selected in list...
|
by: Lie |
last post by:
Hi all,
I have problem in getting selectedindex of multiple listbox selection in a
datagrid. I have a listbox with multiple selection mode inside datagrid. In
Edit mode, I need to get back all...
|
by: sab |
last post by:
Hi,
We have a web form with a listbox. The listbox is a multiple select listbox
and has data that looks something like:
ALL
Unit 1
Unit 2
Unit 3
Note: "ALL" is always the first item in...
|
by: Dany P. Wu |
last post by:
Hi everyone,
One of my Windows forms contain two listbox controls, with Add and Remove
buttons between them.
The idea is to allow users to select multiple items from one ListBox, click
the...
|
by: jim Bob |
last post by:
Hi,
I have a form with a list box that shows the contents of a table and
managed to create an add record button with the wizard.
(DoCmd.GoToRecord , , acNewRec)
Now i want to make a delete...
|
by: kimiraikkonen |
last post by:
Hi,
I have an app which has a listbox and when i double click an
associated fileS, i want their paths to be added into listbox in my
application.
This code works good when i try to open a...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |