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

ItemsSelected not working with ListBox

P: n/a
I'm not sure if this is the result of the postback behavior or my own
code, but for some reason my onclick function is not detecting listbox
selections (It's meant to delete files uploaded to the server).

The RemoveFiles function is being executed, bu I have a feeling the
selections are being cleared beforehand.

There is a Page_Load function which repopulates the listbox. Could
this be getting in the way?
Here is the PageLoad...

void Page_Load(Object S, EventArgs E)
{
ListFiles();
}

And basically, here is my listbox:

<asp:ListBox ID="FB" Width="100%" SelectionMode="Multiple""
runat="server" Font-Size="Small" Rows="5" />

My button:

<asp:button OnClick="RemoveFiles" ID="RemoveButton" runat="server"
Text="Remove File(s)" />

Here is the function which is not seeing the item selections:

void RemoveFiles(object sender, EventArgs e)
{
int i = 0;
String filename = "";
for (i = 0; i < (FB.Items.Count); i++)
{
if (FB.Items[i].Selected) // FB is the
{ // never gets here...
filename = FB.Items[i].Text.ToString();
System.IO.File.Delete(Session["FilePath"] + "\\" +
filename);
}
}
}
Thanks...

Jul 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

If you cleare the list and repopulate again (in the load) then the selections
are lost. As control events occur after load you cannot reach selected elements.

Regards, Alex
[TechBlog] http://devkids.blogspot.com
Jul 18 '07 #2

P: n/a
try something like this and see if it works

for (int i = 0; i < listBox.Items.Count; i++)
{
if (listBox.Items[i].Selected)
{
// List the selected items
listBox += listBox.Items[i].Value + ",";
}
}

this will get all of your selected items in your list box,
--
Mike
'IGotYourDotNet'
http://igotyourdotnet.blogspot.com/

<Pr***************@gmail.comwrote in message
news:11**********************@o11g2000prd.googlegr oups.com...
I'm not sure if this is the result of the postback behavior or my own
code, but for some reason my onclick function is not detecting listbox
selections (It's meant to delete files uploaded to the server).

The RemoveFiles function is being executed, bu I have a feeling the
selections are being cleared beforehand.

There is a Page_Load function which repopulates the listbox. Could
this be getting in the way?
Here is the PageLoad...

void Page_Load(Object S, EventArgs E)
{
ListFiles();
}

And basically, here is my listbox:

<asp:ListBox ID="FB" Width="100%" SelectionMode="Multiple""
runat="server" Font-Size="Small" Rows="5" />

My button:

<asp:button OnClick="RemoveFiles" ID="RemoveButton" runat="server"
Text="Remove File(s)" />

Here is the function which is not seeing the item selections:

void RemoveFiles(object sender, EventArgs e)
{
int i = 0;
String filename = "";
for (i = 0; i < (FB.Items.Count); i++)
{
if (FB.Items[i].Selected) // FB is the
{ // never gets here...
filename = FB.Items[i].Text.ToString();
System.IO.File.Delete(Session["FilePath"] + "\\" +
filename);
}
}
}
Thanks...

Jul 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.