Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 12, 2012 04:43 PM by jplotz
Jun 12, 2012 03:36 PM|LINK
My issue is I have a Dropdownlist with its selected value being populated by a querystring. I have a home page and a products page on my site. on the homepage you can click an image that contains the query to populate the dropdownlist, and it works fine,
but if you click on the Products tab to view the products page with the same dropdownlists and all i get this error:
A critical error has occurred.Object reference not set to an instance of an object. Since my code is in the databound of DDL1 I need to ignore this code if you
just click the Products tab from the site, that does not contain a query. I am not sure how to go about this.
I would appreciate any help.
here is my code.
item.Value = Request.QueryString("id").ToString()
Jun 12, 2012 04:12 PM|LINK
try placing a null check for example
isnot nothing andalso not string.isNullOrEmpty(Request.QueryString("id"))
For Each item As ListItem In DropDownList1.Items
= Request.QueryString("id").ToString() Then
Jun 12, 2012 04:37 PM|LINK
First try checking if the Query String is not Nott... Only if its Not Null then Convert it to string
This must be the source of the exception
Jun 12, 2012 04:43 PM|LINK
Thanks Mudasir, This works perfectly!