S
shapper
Hello,
I created a DropDownList in runtime and added to a panel:
Private Sub ddlCity_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles ddlCity.Init
ddlCity.ID = "ddlCity"
For Each city As City In [Enum].GetValues(GetType(City))
ddlCity.Items.Add(New ListItem(City2String(city,
CurrentCulture), city.ToString))
Next city
End Sub
I am just filling the DropDownList with the values of an Enum.
Now I want to make the selected value of the list equal to the one
save in property of type City in Profile.City:
ddlCity.Items.FindByValue(Profile.City.ToString).Selected = True
I get the error:
System.NullReferenceException: Object reference not set to an instance
of an object.
My Page_Load has the following code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
pMyPanel.Controls.Add(ddlCity)
pMyPanel.Controls.Add(tbName)
Response.Write(ddlCity.Items.Count.ToString) >>>>
This gives me 0!
Response.Write(Profile.City.ToString) >>>>
This gives me London
ddlCity.Items.FindByValue(Profile.City.ToString).Selected =
True
tbName.Text = Profile.Name
End Sub
I don't have any problems with the TextBox. Only with the
DropDownList.
Could somebody help me out?
I don't know what else to try.
Thanks,
Miguel
I created a DropDownList in runtime and added to a panel:
Private Sub ddlCity_Init(ByVal sender As Object, ByVal e As
EventArgs) Handles ddlCity.Init
ddlCity.ID = "ddlCity"
For Each city As City In [Enum].GetValues(GetType(City))
ddlCity.Items.Add(New ListItem(City2String(city,
CurrentCulture), city.ToString))
Next city
End Sub
I am just filling the DropDownList with the values of an Enum.
Now I want to make the selected value of the list equal to the one
save in property of type City in Profile.City:
ddlCity.Items.FindByValue(Profile.City.ToString).Selected = True
I get the error:
System.NullReferenceException: Object reference not set to an instance
of an object.
My Page_Load has the following code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Load
pMyPanel.Controls.Add(ddlCity)
pMyPanel.Controls.Add(tbName)
Response.Write(ddlCity.Items.Count.ToString) >>>>
This gives me 0!
Response.Write(Profile.City.ToString) >>>>
This gives me London
ddlCity.Items.FindByValue(Profile.City.ToString).Selected =
True
tbName.Text = Profile.Name
End Sub
I don't have any problems with the TextBox. Only with the
DropDownList.
Could somebody help me out?
I don't know what else to try.
Thanks,
Miguel