Hi have quite a weird problem on my hands and I am sure I am just overlooking something quite obvious.
I am trying to bind some values to a drop down list. ViewState is definitely enabled. If I add the values to the ddl like this:
<asp:DropDownList ID="ddlUsersList" runat="server" AutoPostBack="true">
<asp:ListItem Text="Bob" />
<asp:ListItem Text="George" />
</asp:DropDownList>
or like this:
ddlUsersList.Items.Add(new ListItem("Bob", "0"));
ddlUsersList.Items.Add(new ListItem("George", "0"));
I dont have an issue. When I select a new user, after the postback that user is still selected. However, when I bind like this:
IEnumerable<GetUsers_Result> result = context.GetUsers("fred", (int)UserTypes.All, (int)UserStatus.Active, false);
foreach (GetUsers_Result r in result)
ddlUsersList.Items.Add(new ListItem(r.Surname + ", " + r.Forename, ""));
Whenever I select a new value, after the postback it selects the first result?
Please can someone help me figure this out.
Update: The BindUsers() method is called only once (I have used a break point to check) and it is called on the page load event and like this:
if (!Page.IsPostBack)
BindUsers();