<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridViewExample5.aspx.cs" Inherits="GridViews.GridViewExample5" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>GridView Example 5</title>
This allows the Listbox control
to create a postback (for server processing) that
fires the SelectedIndexChanged event in the CodeBehind.
</head>
<body bgcolor="#99ccff">
<h3>This GridView example
demonstrates sorting the data.</h3>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="#CC0000">Select
Sort</asp:Label>
<br />
<asp:ListBox ID="lstSortType" runat="server" AutoPostBack="True" Width="175px"
Height="83px" OnSelectedIndexChanged="lstSortType_SelectedIndexChanged">
<asp:ListItem Value="ProductNumber">Product No</asp:ListItem>
<asp:ListItem Value="Description">Description</asp:ListItem>
The values are used in the CodeBehind
for an SQL statement that sorts the records returned in the query. These
need to be the same as the database fields.
<asp:ListItem Value="QOH">Quantity On Hand</asp:ListItem>
<asp:ListItem Value="Price">Price</asp:ListItem>
</asp:ListBox>
<br /> <br />
<asp:GridView ID="gvProducts" runat="server" AutoGenerateColumns="False" ShowFooter="True">
<Columns>
<asp:BoundField DataField="ProductNumber" HeaderText="Product Number" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:BoundField DataField="QOH" HeaderText="QOH" />
<asp:BoundField DataField="Price" DataFormatString="{0:c}" HeaderText="Price" />
</Columns>
</asp:GridView>
</form>
</body>
</html>