ASP.NET SqlDataSource - Using return parameter values from Stored Procedure

SqlDataSource - Using return parameter values from stored procedure
StoredProcedureReturnParameter.aspx

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Text" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    void GridView1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    { 
        StringBuilder textBuilder = new StringBuilder();
        foreach(System.Data.SqlClient.SqlParameter param in e.Command.Parameters)
        {
            textBuilder.Append(Server.HtmlEncode(param.ParameterName)+": Value=");
            textBuilder.Append(Server.HtmlEncode(param.Value.ToString()) + " [");
            textBuilder.Append(Server.HtmlEncode(param.Value.GetType().ToString())+ "]");
            Label1.Text = textBuilder.ToString();
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>SqlDataSource - using return parameter values from Stored Procedure</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">SqlDataSource Example: Stored Procedure And Return Parameter</h2>
        <asp:SqlDataSource 
            ID="SqlDataSource1"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="GetProducts"
            SelectCommandType="StoredProcedure"
            OnSelected="GridView1_Selected"
            >
            <SelectParameters>
                <asp:Parameter Direction="ReturnValue" Name="ReturnParameter" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:Label 
            ID="Label1" 
            runat="server"
            Font-Bold="true"
            Font-Italic="true"
            Font-Size="Large"
            ForeColor="Crimson"
            >
        </asp:Label>
        <br /><br />
        <asp:GridView 
            ID="GridView1"
            runat="server"
            DataSourceID="SqlDataSource1"
            AutoGenerateColumns="true"
            AllowPaging="true"
            PageSize="10"
            BorderColor="Salmon"
            Font-Names="Comic Sans MS"
            Width="650"
            >
            <HeaderStyle BackColor="OrangeRed" ForeColor="Snow" Height="45"/>
            <RowStyle BackColor="DeepPink" ForeColor="Snow" Font-Italic="true" />
            <PagerStyle 
                Height="45" 
                HorizontalAlign="Right" 
                BackColor="RosyBrown"
                Font-Bold="true"
                Font-Size="X-Large"
                ForeColor="Snow"
                />
            <PagerSettings Mode="Numeric" />
        </asp:GridView>
    </div>
    </form>
</body>
</html>
GetProducts [Stored Procedure]

CREATE PROCEDURE [dbo]. [GetProducts]
AS
SELECT ProductID, ProductName, QuantityPerUnit, UnitPrice FROM Products

DECLARE @Count smallint
SELECT @Count = Count(ProductID) FROM Products
RETURN @Count
More asp.net examples