Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropdownList Selected

Status
Not open for further replies.

Javamahn

Technical User
Mar 14, 2001
143
US
I am very new to VB code but I have created some basic applications using Visual Web Developer 2005. I currently have a Gridview that filters using a dropdown. The dropdown is populated using a SQLDatasource of users. I am currently using the code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DropDownList1.ClearSelection()
DropDownList1.Items.FindByText(User.Identity.Name).Selected = True
End Sub

This gives me an error "Object reference not set to an instance of an object."

Whats am I doing wrong? As I said I am new so please don't be too harsh as I am sure it is a very basic mistake that I am making. Thank you for any help.
 
Step through the application with the debugger and tell us what these 3 items contain:

1. User.Identity.Name
2. DropDownList1.Items.FindByText(User.Identity.Name)
3. DropDownList1.Items.Count


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top