Mega Code Archive

 
Categories / ASP.Net / ADO Database
 

Adding Indicators to display Sorting Direction

<%@ Page Language="C#" %> <script runat="server">     void deptView_RowCreated(object sender, GridViewRowEventArgs e)     {         if (e.Row.RowType == DataControlRowType.Header)         {             string imageUrl = (deptView.SortDirection==SortDirection.Ascending ?"Asc.gif" :"Desc.gif");                     for(int i=0; i<deptView.Columns.Count; i++)              {                 string columnExpression = deptView.Columns[i].SortExpression;                 if (columnExpression != "" && columnExpression == deptView.SortExpression)                 {                     Image img = new Image();                     img.ImageUrl =imageUrl;                     e.Row.Cells[i].Controls.Add(img);                                     }             }                 }     }     </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">   <title>Adding Indicators to display Sorting Direction</title> </head> <body>   <form id="form1" runat="server">     <div>       <asp:GridView ID="deptView"                      AllowSorting="true"                      runat="server"                     AutoGenerateColumns="false"                      DataSourceID="deptSource"                     OnRowCreated="deptView_RowCreated">         <Columns>           <asp:BoundField HeaderText="Department ID"                            DataField="DepartmentID"                            SortExpression="DepartmentID" />           <asp:BoundField HeaderText="Name" DataField="Name" SortExpression="Name" />           <asp:BoundField HeaderText="Group Name" DataField="GroupName" />                   </Columns>       </asp:GridView>       <asp:SqlDataSource ID="deptSource"                           Runat="server"                           SelectCommandType="Text"                          SelectCommand="Select DepartmentID, Name, GroupName, ModifiedDate from HumanResources.Department"                           ConnectionString="<%$ConnectionStrings:AdventureWorks%>">       </asp:SqlDataSource>     </div>   </form> </body> </html>