<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.Text" %>
<script runat="server">
void deptSource_Selected(Object sender, System.Web.UI.WebControls.SqlDataSourceStatusEventArgs e)
{
StringBuilder builder = new StringBuilder();
foreach (System.Data.SqlClient.SqlParameter param in e.Command.Parameters)
{
builder.Append(Server.HtmlEncode(param.ParameterName) + "=");
builder.Append(Server.HtmlEncode(param.Value.ToString()) + " (");
builder.Append(Server.HtmlEncode(param.Value.GetType().ToString()) + ")<br>");
}
lblResult.Text = "Output Parameter : " + builder.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Handling Output Parameters from a Stored Procedure</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="deptView" AllowSorting="true" AllowPaging="true" Runat="server"
DataSourceID="deptSource" DataKeyNames="DepartmentID"
AutoGenerateColumns="False" HeaderStyle-HorizontalAlign="Center" HeaderStyle-Font-Bold="True"
HeaderStyle-BackColor="blue" HeaderStyle-ForeColor="White">
<Columns>
<asp:BoundField ReadOnly="true" HeaderText="Department ID" DataField="DepartmentID" SortExpression="DepartmentID" />
<asp:BoundField HeaderText="Name" DataField="Name" SortExpression="Name" />
<asp:BoundField HeaderText="Group Name" DataField="GroupName" SortExpression="GroupName" />
<asp:BoundField HeaderText="ModifiedDate" DataField="ModifiedDate" SortExpression="ModifiedDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="deptSource" Runat="server" SelectCommandType="StoredProcedure"
SelectCommand="GetDepartments"
ConnectionString="<%$ ConnectionStrings:AdventureWorks%>" OnSelected="deptSource_Selected">
<SelectParameters>
<asp:Parameter Direction="Output" Name="Count" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label runat="server" Font-Bold="true" ID="lblResult" />
</form>
</body>
</html>
|