I am trying to figure out how to use AJAX to make my webform automatically update. In my project, I have a dropdownlist that has models of cars. When one of them is selected, and a button is clicked, the program fill a gridView with the records received from the SQL statement. I was wondering if there was any way to be able to make this refresh automatically, and if so how? Here's my asp.net code (code-behind is c#).
<form id="form1" runat="server">
<div>
<asp:GridView ID="gdvCars" runat="server" AutoGenerateColumns="False" DataSourceID="carConnection">
<Columns>
<asp:BoundField DataField="VIN" HeaderText="VIN" SortExpression="VIN" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
<asp:BoundField DataField="Color" HeaderText="Color" SortExpression="Color" />
<asp:BoundField DataField="MSRP" HeaderText="MSRP" SortExpression="MSRP" />
<asp:BoundField DataField="Price_Sold" HeaderText="Price_Sold" SortExpression="Price_Sold" />
</Columns>
</asp:GridView>
<asp:DropDownList ID="ddlTables" runat="server" OnSelectedIndexChanged="ddlTables_SelectedIndexChanged">
<asp:ListItem>Select All</asp:ListItem>
<asp:ListItem Value="SRXConnection">SRX</asp:ListItem>
<asp:ListItem Value="CTSConnection">CTS</asp:ListItem>
<asp:ListItem Value="CTSVConnection">CTS-V</asp:ListItem>
<asp:ListItem Value="STSConnection">STS</asp:ListItem>
<asp:ListItem Value="CruzeConnection">Cruze</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="carConnection" runat="server" ConnectionString="<%$ ConnectionStrings:newKroegedlConnectionString %>" SelectCommand="SELECT [VIN], [Model], [Year], [Color], [MSRP], [Price Sold] AS Price_Sold FROM [tCar]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SRXConnection" runat="server" ConnectionString="<%$ ConnectionStrings:newKroegedlConnectionString %>" SelectCommand="SELECT [VIN], [Model], [Color], [Year], [MSRP], [Price Sold] AS Price_Sold FROM [tCar] WHERE ([Model] = @Model)">
<SelectParameters>
<asp:Parameter DefaultValue="SRX" Name="Model" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="CTSConnection" runat="server" ConnectionString="<%$ ConnectionStrings:newKroegedlConnectionString %>" SelectCommand="SELECT [VIN], [Model], [Color], [Year], [MSRP], [Price Sold] AS Price_Sold FROM [tCar] WHERE ([Model] = @Model)">
<SelectParameters>
<asp:Parameter DefaultValue="CTS" Name="Model" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="CTSVConnection" runat="server" ConnectionString="<%$ ConnectionStrings:newKroegedlConnectionString %>" SelectCommand="SELECT [VIN], [Model], [Color], [Year], [MSRP], [Price Sold] AS Price_Sold FROM [tCar] WHERE ([Model] = @Model)">
<SelectParameters>
<asp:Parameter DefaultValue="CTS-V" Name="Model" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="STSConnection" runat="server" ConnectionString="<%$ ConnectionStrings:newKroegedlConnectionString %>" SelectCommand="SELECT [VIN], [Model], [Color], [Year], [Price Sold] AS Price_Sold, [MSRP] FROM [tCar] WHERE ([Model] = @Model)">
<SelectParameters>
<asp:Parameter DefaultValue="STS" Name="Model" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="CruzeConnection" runat="server" ConnectionString="<%$ ConnectionStrings:newKroegedlConnectionString %>" SelectCommand="SELECT [VIN], [Model], [Color], [Year], [MSRP], [Price Sold] AS Price_Sold FROM [tCar] WHERE ([Model] = @Model)">
<SelectParameters>
<asp:Parameter DefaultValue="Cruze" Name="Model" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Button ID="btnChangeView" runat="server" Text="Button" OnClick="btnChangeView_Click" />
</div>
</form>