Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET/VB dropdownlist not properly populating gridview
    primarykey
    data
    text
    <p>I'm rather new to ASP.NET, but I have to create a .aspx form with VB that when selecting a customer from the ddl, it will populate gridview with the customer's orders from an Access database.</p> <p>So far, my problem is that when I try and select any other customer than the first one, the gridview doesn't repopulate with new information. Rather it stays stuck on the first customer's information.</p> <p>Here's what I have so far:</p> <pre><code>&lt;%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Technical_Challenge.WebForm1" %&gt; &lt;!DOCTYPE html&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;Technical Challenge&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;asp:Label ID="Label1" runat="server" Text="Customers"&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="CustomerName" DataValueField="CustomerID"&gt; &lt;/asp:DropDownList&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:TechChallengeConnectionString %&gt;" ProviderName="&lt;%$ ConnectionStrings:TechChallengeConnectionString.ProviderName %&gt;" SelectCommand="SELECT [CustomerID], [CustomerName] FROM [Customers] ORDER BY [CustomerName]"&gt;&lt;/asp:SqlDataSource&gt; &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="&lt;%$ ConnectionStrings:TechChallengeConnectionString %&gt;" ProviderName="&lt;%$ ConnectionStrings:TechChallengeConnectionString.ProviderName %&gt;" SelectCommand="SELECT * FROM [Orders] WHERE ([CustomerID] = ?)"&gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter ControlID="DropDownList1" Name="CustomerID" PropertyName="SelectedValue" Type="Int32" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;br /&gt; &lt;asp:Label ID="CustomerOrdersLabel" runat="server" Text="Customer Orders"&gt; &lt;/asp:Label&gt; &lt;br /&gt; &lt;asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="OrderID" DataSourceID="SqlDataSource2" ForeColor="#333333" GridLines="None"&gt; &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="OrderID" HeaderText="OrderID" InsertVisible="False" ReadOnly="True" SortExpression="OrderID" /&gt; &lt;asp:BoundField DataField="CustomerID" HeaderText="CustomerID" SortExpression="CustomerID" /&gt; &lt;asp:BoundField DataField="OrderPrice" HeaderText="OrderPrice" SortExpression="OrderPrice" /&gt; &lt;/Columns&gt; &lt;EditRowStyle BackColor="#999999" /&gt; &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt; &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt; &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt; &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" /&gt; &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt; &lt;SortedAscendingCellStyle BackColor="#E9E7E2" /&gt; &lt;SortedAscendingHeaderStyle BackColor="#506C8C" /&gt; &lt;SortedDescendingCellStyle BackColor="#FFFDF8" /&gt; &lt;SortedDescendingHeaderStyle BackColor="#6F8DAE" /&gt; &lt;/asp:GridView&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The code-behind:</p> <pre><code>Public Class WebForm1 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub SqlDataSource1_Selecting(sender As Object, e As SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting End Sub End Class </code></pre> <p>Any help would be greatly appreciated. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload