C
Celine
I have a webform with multiple panels with textboxes, dropdownlists,
radiobuttonlists, etc. The user navigates through the panels and then
submits the information at the end.
The first panel contains a text box where users can enter a search term. A
"next" button displays the following panel causing a stored procedure to
populate a dropdown list. The dropdown list displays the results of the
search, and requires users to select an option.
The problem is that when the user navigates forward to other panels, the
selected option in the dropdown list is not retained. The first entry in
the dropdownlist is what is submitted to the database, not the option the
user selected. This is because I am populating the list when
Page.IsPostBack. When I've tried to populate the list when ! IsPostBack is
true, it doesn't populate correctly. Instead of displaying options based on
the search term, it displays every item in the database. However, in this
scenario, the selected value is retained.
How can I get around this problem?
Here is the code from the codebehind page
if (Page.IsPostBack)
{
//populate dropOwnerSelect
SqlCommand cmdSelect;
SqlDataReader dtrOwner;
cmdSelect = new SqlCommand( "sp_selectCompanies", conProjData);
cmdSelect.CommandType = CommandType.StoredProcedure;
cmdSelect.Parameters.Add("@name", txtOwner.Text);
conProjData.Open();
dtrOwner = cmdSelect.ExecuteReader();
dropOwnerSelect.DataSource = dtrOwner;
dropOwnerSelect.DataValueField = "CompanyID";
dropOwnerSelect.DataTextField = "CompanyName";
dropOwnerSelect.DataBind();
dtrOwner.Close();
conProjData.Close();
}
radiobuttonlists, etc. The user navigates through the panels and then
submits the information at the end.
The first panel contains a text box where users can enter a search term. A
"next" button displays the following panel causing a stored procedure to
populate a dropdown list. The dropdown list displays the results of the
search, and requires users to select an option.
The problem is that when the user navigates forward to other panels, the
selected option in the dropdown list is not retained. The first entry in
the dropdownlist is what is submitted to the database, not the option the
user selected. This is because I am populating the list when
Page.IsPostBack. When I've tried to populate the list when ! IsPostBack is
true, it doesn't populate correctly. Instead of displaying options based on
the search term, it displays every item in the database. However, in this
scenario, the selected value is retained.
How can I get around this problem?
Here is the code from the codebehind page
if (Page.IsPostBack)
{
//populate dropOwnerSelect
SqlCommand cmdSelect;
SqlDataReader dtrOwner;
cmdSelect = new SqlCommand( "sp_selectCompanies", conProjData);
cmdSelect.CommandType = CommandType.StoredProcedure;
cmdSelect.Parameters.Add("@name", txtOwner.Text);
conProjData.Open();
dtrOwner = cmdSelect.ExecuteReader();
dropOwnerSelect.DataSource = dtrOwner;
dropOwnerSelect.DataValueField = "CompanyID";
dropOwnerSelect.DataTextField = "CompanyName";
dropOwnerSelect.DataBind();
dtrOwner.Close();
conProjData.Close();
}