<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridView.aspx.cs" Inherits="GridView" %>
<!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 ></asp:Label><br />
        <br />
        d</div>
    </form>
</body>
</html>

 

 

cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class GridView : System.Web.UI.Page
{
    string sortexp = "";//排序表达式
    string sortdir = "";//排序方向
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            foreach (TableCell tc in e.Row.Cells)
            {
                //这种方法直接新加一个控件,也可以换成图片              
                if (tc.Controls.Count > 0)//这里要判断一下此时是不是已经生成了linkbutton
                {
                    string s1 = ((LinkButton)tc.Controls[0]).Text;
                    //样式Webdings是123都有自己对应的图片
                    ((LinkButton)tc.Controls[0]).Text = s1.Replace(s1, s1 + "<font face='Webdings'>5</font>");
                    //倒序的样式
                    if (tc.Controls.Count > 0 && tc.Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataControlLinkButton")
                    {

                        if (((LinkButton)tc.Controls[0]).CommandArgument == sortexp)
                        {                 
                            string s2 = ((LinkButton)tc.Controls[0]).Text;
                            if (sortdir == "Descending")
                            {
                                ((LinkButton)tc.Controls[0]).Text = s2.Replace("5", "6");
                            }
                        }
                    }
                }
            }
        }
    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        sortexp = e.SortExpression.ToString();
        sortdir = e.SortDirection.ToString();

    }
}

相关文章: