I have a ListView that populates and displays a user's data (via a profile system in VWD 2008) during Page_Load and also when I go from the EditItemTemplate to the ItemTemplate. Then when I go to the edit screen again, my DropDownList and RadioButtonList controls display the first items in the corresponding tables instead of the correct profile values. I don't understand why the controls populate correctly the first and second times but not on the third time (that's right, the third time is NOT a charm); I hope someone can help me understand how to solve this problem.
ItemTemplate:
Code:
<asp:DropDownList ID="ddlTState" AppendDataBoundItems="True" DataSourceID="srcState"
DataTextField="StateName" DataValueField="StateName" Enabled="False" TabIndex="125"
runat="server" />
<asp:DropDownList ID="ddlTState" AppendDataBoundItems="True" DataSourceID="srcState"
DataTextField="StateName" DataValueField="StateName" Enabled="False" TabIndex="125"
runat="server" />
EditItemTemplate:
Code:
<asp:DropDownList ID="ddlEState" AppendDataBoundItems="true" DataSourceID="srcState"
DataTextField="StateName" DataValueField="StateName" TabIndex="125" runat="server">
<asp:ListItem Text="--State--" Value="" />
<asp:DropDownList ID="ddlEState" AppendDataBoundItems="true" DataSourceID="srcState"
DataTextField="StateName" DataValueField="StateName" TabIndex="125" runat="server">
<asp:ListItem Text="--State--" Value="" />
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
lsv = Util.FindChild(Me, "lsvProfile") 'Util.FindChild instead of FindControl
'If Not IsPostBack Then
ddl = Util.FindChild(lsv, "ddlEState")
If ddl IsNot Nothing Then ddl.SelectedValue = Profile.State
ddl = Util.FindChild(lsv, "ddlTState")
If ddl IsNot Nothing Then ddl.SelectedValue = Profile.State
'End If
End Sub