Hoping someone can help end the misery.
I have a an aspx page that displays customer contact info at the top followed by a databound dropdownlist that contains a list of products the customer has purchased. The bottom of the page contains a label for each month of the current fiscal year showing total sales of the selected product per month.
When the page is first loaded, 3 ID's are passed from the previous page through a querystring to give me the id's required to load each of the 3 sections. Based on the 3rd one, a default product is selected in the dropdownlist and the labels are loaded accordingly.
Here's the problem:
Whenever I click in the dropdownlist to select a different product the page reloads and the customer data is gone, the dropdownlist is empty, and the labels show the previous information.
My OnSelectedIndexChanged event doesn't seem to connect with the dropdownlist. I have assigned hardcoded text to a label in the handler and it never gets set.
How can I refresh my page showing the new data based on the value selected in the dropdownlist?
Here's the code I am working with:
<SCRIPT language="
vb" runat="server">
Dim pgSalesmanID As Integer
Dim pgCustomerID As Integer
Dim pgProductID As Integer
Dim curPos as Integer = 0
SUB Page_Load(sender as Object, e as EventArgs)
If (Request.QueryString("sID") <> "") then
pgSalesmanID = Convert.ToInt32(Request.QueryString("sID"))
End if
If (Request.QueryString("cID") <> "") then
pgCustomerID = Convert.ToInt32(Request.QueryString("cID"))
End if
If (Request.QueryString("pID") <> "") then
pgProductID = Convert.ToInt32(Request.QueryString("pID"))
End if
If (Request.QueryString("pos") <> "") then
curPos = Convert.ToInt32(Request.QueryString("pos"))
End if
IF NOT Page.isPostBack then
bindSQL()
END IF
END SUB
SUB productList_OnChange (sender As Object, e As EventArgs)
pgProductID = productList.SelectedItem.Value
bindSQL()
END SUB
SUB bindSQL()
loadProductList()
END SUB
SUB loadProductList()
Dim cn as SQLConnection
Dim cmd as SQLCommand
Dim rdr as SQLDataReader
Dim sConnectString as String = "connectionString"
Dim sSql as String = "sp_mySp '8, 250, 11"
cn = New SQLConnection(sConnectString)
Try
cn.Open()
cmd = New SQLCommand(sSQL, cn)
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
productList.DataSource = rdr
productList.DataBind()
Catch myException As Exception
Response.Write("An error has occurred trying to load
Product: " & myException.ToString())
Finally
If Not rdr Is Nothing Then
rdr.Close()
End If
productList.Items.Insert(0, "Select Product")
If (pgProductID <> 0) then
productList.SelectedValue = pgProductID
Else
productList.SelectedIndex = 0
End If
End Try
END SUB
</SCRIPT>
Then my grid:
<ASP:DropDownList id="productList" width="250"
DataValueField="ProductID"
DataTextField="ProductCode"
AutoPostBack="true"
OnSelectedIndexChanged="productList_OnChange"
runat="server"/>
I hope my question isn't to confusing. Thanks for any help you can provide.