Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Gridview Sorting using attribute [Source Code]

, 30 Aug 2013
Sorting GridView using attribute property of GridView
demo.zip
demo of my project
App_Code
App_Data
database
database.bak
Thumbs.db
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;<asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowSorting="true"  OnSorting="gvcontent_Sorting"            Width="100px"   >
            <Columns>
                <asp:TemplateField>
                
           <ItemTemplate>
        
           </ItemTemplate>           
           </asp:TemplateField>  
             
                
               <asp:TemplateField HeaderText="History ID" SortExpression="History_ID">
                                   <ItemTemplate><asp:Label runat="server" ID="lblRewards_Type" Text='<%# Eval("History_ID") %>' /></ItemTemplate>
                                  
                                    <HeaderStyle ForeColor="Maroon" Font-Underline="True" />
               </asp:TemplateField>
             
               <asp:TemplateField HeaderText="Admin id" SortExpression="admin_ID">
                                   <ItemTemplate><asp:Label runat="server" ID="lblAlias" Text='<%# Eval("admin_ID") %>' /></ItemTemplate>
                                  
                                    <HeaderStyle ForeColor="Maroon" Font-Underline="True" />
               </asp:TemplateField>
                <asp:TemplateField HeaderText="Ip address" SortExpression="Ip_address">
                                   <ItemTemplate><asp:Label runat="server" ID="dsd" Text='<%# Eval("Ip_address") %>' /></ItemTemplate>
                                  
                                    <HeaderStyle ForeColor="Maroon" Font-Underline="True" />
               </asp:TemplateField>
                <asp:TemplateField HeaderText="Mac Address" SortExpression="Mac_Address">
                                   <ItemTemplate><asp:Label runat="server" ID="dsd" Text='<%# Eval("Mac_Address") %>' /></ItemTemplate>
                                  
                                    <HeaderStyle ForeColor="Maroon" Font-Underline="True" />
               </asp:TemplateField>
                  <asp:TemplateField HeaderText="Login datetime" SortExpression="Login_datetime">
                                   <ItemTemplate><asp:Label runat="server" ID="dsd" Text='<%# Eval("Login_datetime") %>' /></ItemTemplate>
                                  
                                    <HeaderStyle ForeColor="Maroon" Font-Underline="True" />
               </asp:TemplateField>
               
               
                                                   
                </Columns>
        </asp:GridView>
        &nbsp;
        
        <asp:Label ID="lblmsg" runat="server" Text="Label" Visible="False"></asp:Label>
        
        &nbsp;&nbsp;
    
    </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

AJD-salute
Web Developer
India India
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 31 Aug 2013
Article Copyright 2013 by AJD-salute
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid