Advertisement

02.14.2008 at 07:17AM PST, ID: 23163126
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Listbox control question ASP.net C#
Tags: C# asp.net
I'd like to search a listbox bound to a SQL query during load. I have the text box and a search button. First time I enter text and hit search. The selected item changes in listbox. One problem I hit I use the selectedindexchange envent to load another textbox from the selected value in listbox. When I use search button that event doesn't fire. The other problem I'm having is if I enter text again to search I get the null reference errror. Any insight would be appreciated.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
protected void TempSearchTB_TextChanged(object sender, EventArgs e)
    {
        ListBox lst = (ListBox)FormView1.FindControl("ListBox1");
 
        TextBox searchstring = (TextBox)FormView1.Row.FindControl("TempSearchTB");
        
        String searchText = searchstring.Text;
       
        lst.ClearSelection();
        try
        {
            lst.Items.FindByValue(searchText).Selected = true;
            
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
      
    }
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: national_fulfillment
Solution Provided By: national_fulfillment
Participating Experts: 2
Solution Grade: A
Views: 287
Translate:
Loading Advertisement...
02.14.2008 at 07:30AM PST, ID: 20894078

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.14.2008 at 07:33AM PST, ID: 20894112

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.14.2008 at 08:12AM PST, ID: 20894551

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.14.2008 at 08:13AM PST, ID: 20894564

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.14.2008 at 08:20AM PST, ID: 20894617

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.19.2008 at 12:57PM PST, ID: 20932504

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.19.2008 at 01:54PM PST, ID: 20933041

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.20.2008 at 05:50AM PST, ID: 20937690

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.20.2008 at 05:55AM PST, ID: 20937726

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.21.2008 at 05:49AM PST, ID: 20947634

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
02.14.2008 at 07:30AM PST, ID: 20894078

Rank: Master

I had a similar situation, and I wound up using an alternative method, which I'll describe below.  If it won't work for you, can you tell me the line you get the null exception on?

Step 1: Use ListSearch extender from AJAX Control Toolkit to search the listbox.
Step 2: Have a button below the listbox "Load Selection".  AutoPostBack of the ListBox won't work with the ListSearch.

ListSearch: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ListSearch/ListSearch.aspx
 
02.14.2008 at 07:33AM PST, ID: 20894112

Rank: Wizard

To answer one of your questions/problems. The SelectedIndexChanged event does not fire whenever you programmatically change the selected item of a list box. In that situation, you would need to call a method that does what you want. You could create the method so that the SelectedIndexChanged event just calls it as well instead of duplicating the code in two different locations.

You didn't specify what line the null reference is occuring on but it appears that the problem will arise if you search for an item that doesn't exist due to the line:

lst.Items.FindByValue(searchText).Selected = true;

In the above line of code, if the list box does not contain the value searched for, it will return Null which would thus make the ".Selected" property invalid and throw the null reference error. Add some code to check to see if the item exists before accessing the Selected property of the item:

1:
2:
3:
4:
5:
ListBoxItem li = lst.Items.FindByValue(searchText)
if(li)
{
  li.Selected = true;
}
Open in New Window
 
02.14.2008 at 08:12AM PST, ID: 20894551
it's returning a null on the listbox itself. I debugged it and there is a value in the searchtext.
 
02.14.2008 at 08:13AM PST, ID: 20894564
lst.Items.FindByValue(searchText).Selected = true;

this is the line that returns null on the second search.
 
02.14.2008 at 08:20AM PST, ID: 20894617

Rank: Wizard

Read my solution, it explains why you would get an error on that line and how to work around it.
 
02.19.2008 at 12:57PM PST, ID: 20932504
this does stop the execption but doesn't solve the problem because the item is in the listbox and it's returning a null no matter what.
1:
2:
3:
4:
5:
ListItem li = lst.Items.FindByValue(searchText);
        if (li!=null)
        {
            lst.Items.FindByValue(searchText).Selected = true;
        }
Open in New Window
 
02.19.2008 at 01:54PM PST, ID: 20933041

Rank: Wizard

Can you set a break point on line 2 of the above code and take a look at what's in lst.Items using the immediate window or one of the other debug windows?
Assisted Solution
 
02.20.2008 at 05:50AM PST, ID: 20937690
First time I search everything works the way it's suppose to (search value was "test"), but if I try to search again (search value "The State Within") the list is empty. Am I missing some sort of reload function. I assumed ones the listbox was loaded the values stayed am I wrong?

Thanks for your advice/help so far.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
************************Debug FIRST TIME:**********************
-		li	{test}	System.Web.UI.WebControls.ListItem
-		Attributes	{System.Web.UI.AttributeCollection}	System.Web.UI.AttributeCollection
		Count	0	int
+		CssStyle	{System.Web.UI.CssStyleCollection}	System.Web.UI.CssStyleCollection
+		Keys	{System.Collections.Specialized.ListDictionary.NodeKeyValueCollection}	System.Collections.ICollection {System.Collections.Specialized.ListDictionary.NodeKeyValueCollection}
+		Non-Public members		
		Enabled	true	bool
		Selected	false	bool
		Text	"test"	string
		Value	"test"	string
+		Non-Public members		
-		lst.Items	{System.Web.UI.WebControls.ListItemCollection}	System.Web.UI.WebControls.ListItemCollection
		Capacity	128	int
		Count	126	int
		IsReadOnly	false	bool
		IsSynchronized	false	bool
+		SyncRoot	{System.Web.UI.WebControls.ListItemCollection}	object {System.Web.UI.WebControls.ListItemCollection}
+		Non-Public members		
		searchText	"test"	string
-		this	{ASP.vremail_aspx}	VREmail {ASP.vremail_aspx}
+		[ASP.vremail_aspx]	{ASP.vremail_aspx}	ASP.vremail_aspx
+		base	{ASP.vremail_aspx}	System.Web.UI.Page {ASP.vremail_aspx}
+		ApplicationInstance	{ASP.global_asax}	ASP.global_asax
+		form1	{System.Web.UI.HtmlControls.HtmlForm}	System.Web.UI.HtmlControls.HtmlForm
+		FormView1	{System.Web.UI.WebControls.FormView}	System.Web.UI.WebControls.FormView
+		HyperLink1	{Text = "BBC America Scheduling"}	System.Web.UI.WebControls.HyperLink
+		Image1	{System.Web.UI.WebControls.Image}	System.Web.UI.WebControls.Image
+		Label2	{Text = "Viewer Relations Response Page"}	System.Web.UI.WebControls.Label
+		LinkButton1	{Text = "Records"}	System.Web.UI.WebControls.LinkButton
+		LinkButton2	{Text = "Home"}	System.Web.UI.WebControls.LinkButton
+		Profile	{System.Web.Profile.DefaultProfile}	System.Web.Profile.DefaultProfile
 
 
***********************Debug of Second Search**************
		li	null	System.Web.UI.WebControls.ListItem
-		lst.Items	{System.Web.UI.WebControls.ListItemCollection}	System.Web.UI.WebControls.ListItemCollection
		Capacity	128	int
		Count	126	int
		IsReadOnly	false	bool
		IsSynchronized	false	bool
+		SyncRoot	{System.Web.UI.WebControls.ListItemCollection}	object {System.Web.UI.WebControls.ListItemCollection}
+		Non-Public members		
		searchText	"The State Within"	string
-		this	{ASP.vremail_aspx}	VREmail {ASP.vremail_aspx}
+		[ASP.vremail_aspx]	{ASP.vremail_aspx}	ASP.vremail_aspx
+		base	{ASP.vremail_aspx}	System.Web.UI.Page {ASP.vremail_aspx}
+		ApplicationInstance	{ASP.global_asax}	ASP.global_asax
+		form1	{System.Web.UI.HtmlControls.HtmlForm}	System.Web.UI.HtmlControls.HtmlForm
+		FormView1	{System.Web.UI.WebControls.FormView}	System.Web.UI.WebControls.FormView
+		HyperLink1	{Text = "BBC America Scheduling"}	System.Web.UI.WebControls.HyperLink
+		Image1	{System.Web.UI.WebControls.Image}	System.Web.UI.WebControls.Image
+		Label2	{Text = "Viewer Relations Response Page"}	System.Web.UI.WebControls.Label
+		LinkButton1	{Text = "Records"}	System.Web.UI.WebControls.LinkButton
+		LinkButton2	{Text = "Home"}	System.Web.UI.WebControls.LinkButton
+		Profile	{System.Web.Profile.DefaultProfile}	System.Web.Profile.DefaultProfile
Open in New Window
 
02.20.2008 at 05:55AM PST, ID: 20937726
The values I'm searching for are definately part of the listbox; and just to mention if i search again with the orginal value ("test") all works the way it's suppose to.
 
02.21.2008 at 05:49AM PST, ID: 20947634
I figured it out. My listbox displays one column but the value points to a different column. So I have to switch to using
ListItem li = lst.Items.FindByText(searchText);
all is well now; it worked for my "test" value because that's what I had as it's value "test".  
Anyway thanks for the help; while I'm on the subject does anyone happen to know how to make the search ignore case when looking at the list items?
Accepted Solution
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628