469,625 Members | 1,080 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

ItemsSelected not working with ListBox

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
2 2800
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
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.

Similar topics

1 post views Thread by jagello | last post: by
2 posts views Thread by Sally | last post: by
3 posts views Thread by kaosyeti via AccessMonster.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.