How to select records using StoredProcedure and GridView in asp.net
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 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]
1 2 3 4 5 | CREATE PROCEDURE [dbo]. [GetProducts] AS SELECT PRODUCTID, PRODUCTNAME, QUANTITYPERUNIT, UNITPRICE FROM PRODUCTS |
Output: