How to execute StoredProcedure using SqlDataSource in asp.net
GridViewStoredProcedure.aspx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | <%@ 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 execute StoredProcedure using SqlDataSource in asp.net</title> </head> <body> <form id="form1" runat="server"> <div> <h2 style="color:Navy; font-style:italic;">GridView Example: Execute 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="Salmon" Font-Names="Comic Sans MS" Width="650" > <HeaderStyle BackColor="IndianRed" ForeColor="Snow" Height="45"/> <RowStyle BackColor="DarkSalmon" 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 [StoredProcedure]
1 2 3 4 5 | CREATE PROCEDURE [dbo]. [GetProducts] AS SELECT PRODUCTID, PRODUCTNAME, QUANTITYPERUNIT, UNITPRICE FROM PRODUCTS |
Output: