Select records using StoredProcedure and GridView in asp.net

How to select records using StoredProcedure and GridView in asp.net
GridViewSelectDataStoredProcedure.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>How to select records using StoredProcedure and GridView in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">GridView Example: Select Records Using StoredProcedure</h2>
        <asp:SqlDataSource 
            ID="SqlDataSource1"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="GetProducts"
            SelectCommandType="StoredProcedure"
            >
        </asp:SqlDataSource>
        <asp:GridView 
            ID="GridView1"
            runat="server"
            DataSourceID="SqlDataSource1"
            AutoGenerateColumns="true"
            AllowPaging="true"
            PageSize="10"
            BorderColor="CornflowerBlue"
            Font-Names="Comic Sans MS"
            Width="650"
            >
            <HeaderStyle BackColor="DarkCyan" BorderColor="Cyan" ForeColor="Snow" Height="45"/>
            <RowStyle BackColor="CadetBlue" ForeColor="Snow" Font-Italic="true" />
            <PagerStyle 
                Height="45" 
                HorizontalAlign="Right" 
                BackColor="DodgerBlue"
                Font-Bold="true"
                Font-Size="X-Large"
                ForeColor="Snow"
                />
            <PagerSettings Mode="Numeric" />
        </asp:GridView>
    </div>
    </form>
</body>
</html>
GetProducts [StoredProcedure]
CREATE PROCEDURE [dbo]. [GetProducts]
AS
SELECT PRODUCTID, PRODUCTNAME, QUANTITYPERUNIT, UNITPRICE FROM PRODUCTS







Related asp.net example