Listbox not getting the selected values.
Listbox not getting the selected values.
Listbox not getting the selected values.
Listbox not getting the selected values.
Listbox not getting the selected values.
Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values.
Listbox not getting the selected values. Listbox not getting the selected values.
Listbox not getting the selected values.
Go Back  Xtreme Visual Basic Talk > > > Listbox not getting the selected values.


Reply
 
Thread Tools Display Modes
  #1  
Old 11-07-2008, 10:23 AM
FacJoe FacJoe is offline
Centurion
 
Join Date: Jun 2003
Posts: 107
Post Listbox not getting the selected values.


Here's my code on ASP:

Code:
<asp:UpdatePanel ID="upnl_lstResources" runat="server">                      
    <ContentTemplate>
        <asp:ListBox id="lstResources" runat="server" CssClass="simpleText"
           Width="300px" Height="150px" SelectionMode="Multiple">                   </asp:ListBox>                            
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProjects" EventName="SelectedIndexChanged" />
</Triggers>
                        </asp:UpdatePanel>
Code:
protected void btnSave_Click(object sender, EventArgs e)
{
        foreach(ListItem lst in lstResources.Items)
        {
            if(lst.Selected)
            {
                //DO CODE HERE
            }
        }
}
Listbox "lstResources" is inside an UpdatePanel has AutoPostBack to "false". Selection mode is "Multi". My problem is, I can't get the selected values! I mean, I know they are selected and all, but when I click the "Save" button and run the condition to check which list items have been selected, all of them are set to "Selected=false".

I tried doing this in a blank web page and it works. I can get the selected values just fine. I don't get why in my particular page, I can't get the selected values. The list items are loaded dynamically from a SQL database, and then bound to the a ListItem object w/c is then added to the ListItem collection of the Listbox, but I don't think it's an issue since no value is lost when I click the "Save" button and iterate on each ListItem in the Listbox to check whether the values I loaded are still there. Help!
Reply With Quote
  #2  
Old 11-07-2008, 10:36 AM
wayneph's Avatar
waynephListbox not getting the selected values. wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

Where are you loading the List Items at? If I had to guess, the code to reload the items is being called again, right before the Save and is overwriting your selections. Obviously without seeing the Page_Load or Page_Init functions, I can't be certain, but that is the first thing I would check.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 11-07-2008, 11:06 AM
FacJoe FacJoe is offline
Centurion
 
Join Date: Jun 2003
Posts: 107
Default

Sonuva...LOL.

I just missed out on the "if (!Page.PostBack)" condition on the load event.

I'm such an idiot.

Thank you, Wayne. Kindly close this thread, mods.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Listbox not getting the selected values.
Listbox not getting the selected values.
Listbox not getting the selected values. Listbox not getting the selected values.
Listbox not getting the selected values.
Listbox not getting the selected values.
Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values. Listbox not getting the selected values.
Listbox not getting the selected values.
Listbox not getting the selected values.
 
Listbox not getting the selected values.
Listbox not getting the selected values.
 
-->