I am using the createuserwizard, and have set up my own profile table which hold first name, last etc. In my CreateUserWizard, the field for Vendor is a dropdownlist that is to be populated from a list in a database. I set up the form without the createuserwizard, and everything went skippy, but when I placed it into the wizard, I now cannot access the control of the dropdownlist.
I have tried doing..
Using SqlConnectionAsNew SqlConnection(WebConfigurationManager.ConnectionStrings("Personal").ConnectionString)
Dim VendorID As DropDownList
VendorID = CType(CreateUserWizard1.FindControl("VendorName"), DropDownList)
Dim MyReaderAs SqlDataReader
Dim selAsString =String.Format("SELECT VendorID, Name FROM Vendors")
Dim MyCommandAs SqlCommand
MyCommand =New SqlCommand
MyCommand.CommandText = sel
MyCommand.CommandType = CommandType.Text
MyCommand.Connection = SqlConnection
MyCommand.Connection.Open()
MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConnection)
But when I go to databind, it says:
Object reference not set to an instance of an object.
VendorID.DataSource = MyReader
Line 30: VendorID.DataValueField = "VendorID"
Line 31: VendorID.DataTextField = "Name"
Dim MyReaderAsNewSqlDataReader|||
Sorry, I left that line out of my post, but it was in there. I found the solution to my problem though.
I was originally putting in CreateUserWizard1.FindControl("VendorID"), DropDownList)
THe actual code that worked is...
CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("VendorID"), DropDownList)
Works a charm.
It's always a bugger not knowing these little "tricks"!!
Mick
mickyjtwin:
Sorry, I left that line out of my post, but it was in there. I found the solution to my problem though.
I'm glad you found the solution. In the future, please be sure to copy-and-paste your exact code, not an approximation of it. Otherwise others (such as myself) will spend needless time trying to help you to debug problems that don't exist.
No comments:
Post a Comment