Page 52 - DCAP312_WEB_TECHNOLOGIES_II
P. 52

Web Technologies-II



                   Notes                 </tr>
                                         </ItemTemplate>
                                         <AlternatingItemTemplate>
                                         <tr style= “background color:#EFEFEF”>
                                         <td><asp:Label  runat=  “server”  ID= “lblId”><%#Eval(“ID”)  %></
                                         asp:Label></td>
                                          <td><asp:Label runat= “server” ID= “lblName”><%#Eval(“FirstName”)+
                                         ““+
                                           Eval(“LastName”) %></asp:Label></td>
                                         <td><asp:Label  runat=“server” ID= “lblType”><%#Eval(“ContactTy
                                         pe”) %></asp:Label></td>
                                         <td></td>
                                         </tr>
                                         </AlternatingItemTemplate>
                                 Here Layout template is making header of the control, and Item Template is showing data taken
                                 from table by Binding columns with Label controls, and AlternativeItemTemplate does the same
                                 as Item Template just changing CSS for alternative columns.

                                 Data Pager
                                 To add pagination in the list view, we need to add an asp: Data Pager control, better to put
                                 this control inside Layout Template at the end of the Layout Template. Data Pager control has
                                 many options to show pagination and these are useful too.

                                         <asp:DataPager ID= “ItemDataPager” runat= “server” PageSize= “5”>
                                     <Fields>
                                       <asp:NumericPagerField ButtonCount= “2” />
                                      </Fields>
                                     </asp:DataPager>
                                 Sorting
                                 It  is  very  simple  to  sort  data  in  List  View.  Sort  functionality  is  distinct  in  the  Command
                                 disagreement property of the button that contains the columns to be sorted. It occurs when a
                                 button with its Command Name property set to Sort is click. And we need to make a call to the
                                 Sort method named on sorting="ListView1_Sorting".
                                         // to allow sort if click on the header of the table make
                                         //table header controls clickable
                                         //and give commandname and commandargument
                                         <tr style= “background-color:#E5E5FE”>
                                          <th align= “left”><asp:LinkButton ID= “lnkId” runat= “server”
                                           CommandName= “Sort” CommandArgument= “ID”>Id</asp:LinkButton></th>
                                          <th align= “left”><asp:LinkButton ID= “lnkName” runat= “server”
                                           CommandName=“Sort” CommandArgument=“FirstName”>Name</
                                         asp:LinkButton></th>
                                          <th align= “left”><asp:LinkButton ID= “lnkType” runat= “server”
                                           CommandName=“Sort”CommandArgument=“ContactType”>Type</
                                         asp:LinkButton></th>
                                          <th></th>
                                         </tr>


        46                                LOVELY PROFESSIONAL UNIVERSITY
   47   48   49   50   51   52   53   54   55   56   57