asp.net FormView example: how to use ItemTemplate and Paging
FormViewExample.aspx
  1. <%@ Page Language="C#" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.   
  5. <script runat="server">  
  6.   
  7. </script>  
  8.   
  9. <html xmlns="http://www.w3.org/1999/xhtml">  
  10. <head runat="server">  
  11.     <title>asp.net FormView example: how to use ItemTemplate and Paging</title>  
  12. </head>  
  13. <body>  
  14.     <form id="form1" runat="server">  
  15.     <div>  
  16.         <h2 style="color:Red">Example: FormView</h2>  
  17.         <asp:SqlDataSource   
  18.             ID="SqlDataSource1"  
  19.             runat="server"  
  20.             ConnectionString="<%$ ConnectionStrings:PubsConnectionString %>"  
  21.             SelectCommand="SELECT emp_id, fname, lname, hire_date FROM employee"  
  22.             >  
  23.         </asp:SqlDataSource>  
  24.         <asp:FormView   
  25.             ID="FormView1"  
  26.             runat="server"  
  27.             DataSourceID="SqlDataSource1"  
  28.             DataKeyNames="emp_id"  
  29.             AllowPaging="true"  
  30.             >  
  31.             <HeaderTemplate>  
  32.                 Employee Details  
  33.             </HeaderTemplate>  
  34.             <HeaderStyle  
  35.                  BackColor="DarkBlue"  
  36.                  ForeColor="AliceBlue"   
  37.                  BorderColor="DarkOrange"   
  38.                  BorderStyle="None"  
  39.                  BorderWidth="2"  
  40.                  Font-Size="Medium"  
  41.                  Font-Italic="false"  
  42.                  Font-Bold="true"  
  43.                  Height="35"  
  44.                  HorizontalAlign="Center"  
  45.                  />  
  46.             <ItemTemplate>  
  47.                 <b>Employee ID:</b> <i><%# Eval("emp_id") %></i>  
  48.                 <br />  
  49.                 <b>Employee Name:</b> <i><%# Eval("lname") %> <%# Eval("fname") %></i>  
  50.                 <br />  
  51.                 <b>Hire Date:</b> <i><%# Eval("hire_date") %></i>  
  52.             </ItemTemplate>  
  53.             <RowStyle   
  54.                 BackColor="DodgerBlue"  
  55.                 ForeColor="AliceBlue"  
  56.                 />  
  57.             <PagerSettings Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last" />  
  58.             <PagerStyle BackColor="DarkBlue" ForeColor="AliceBlue" />  
  59.         </asp:FormView>  
  60.     </div>  
  61.     </form>  
  62. </body>  
  63. </html>  




0 comments:

Post a Comment