The Event Handler Function for the button is as follows:
public void selectedItemChanged(object sender, EventArgs e)
{
// Get the value of the currently selected item from the trackerUsers DDL
String selectedUser = trackerUsers.SelectedValue.ToString();
// Parse the value of selectedUser to a function within the scope of the SQL namespace / class
CAR.IDENTITY.user.getName(selectedUser);
}
Every time I debug and watch the value of selectedUser it always defaults to the first item in the list even when I specifically make an alternative choice. I think it's something to do with post back or viewstate but I'm not sure. Can anyone explain what
the issue is and confirm how I fix this?
LTGoldman
Member
64 Points
92 Posts
DDL Item choice resetting when submitting form
Apr 09, 2012 09:49 PM|LINK
Hello I have a DDL defined as:
<asp:DropDownList ID="trackerUsers" runat="server"></asp:DropDownList>
And an ASP Button defined as:
<asp:Button ID="reportBtn" Text="Run Report" runat="server" OnClick="selectedItemChanged" />
The Event Handler Function for the button is as follows:
public void selectedItemChanged(object sender, EventArgs e) { // Get the value of the currently selected item from the trackerUsers DDL String selectedUser = trackerUsers.SelectedValue.ToString(); // Parse the value of selectedUser to a function within the scope of the SQL namespace / class CAR.IDENTITY.user.getName(selectedUser); }Every time I debug and watch the value of selectedUser it always defaults to the first item in the list even when I specifically make an alternative choice. I think it's something to do with post back or viewstate but I'm not sure. Can anyone explain what the issue is and confirm how I fix this?
karthicks
All-Star
31382 Points
5424 Posts
Re: DDL Item choice resetting when submitting form
Apr 10, 2012 04:26 AM|LINK
hi, where are you binding the trackerUsers DropDownList .
if you are binding in Page_load you should do like below .i.e you should not bind the DropDownList on every postback
if(!Page.IsPostBack){
trackerUsers.DataSource=ds;
trackerUsers.DataTextField="Name"; trackerUsers.DataValueField="ID";
trackerUsers.DataBind();}
Karthick S
LTGoldman
Member
64 Points
92 Posts
Re: DDL Item choice resetting when submitting form
Apr 10, 2012 11:21 PM|LINK
This was precisely it; many thanks will mark your response as the answer.