关闭

排序

738人阅读 评论(0) 收藏 举报

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;
using System.Data.SqlClient;

public partial class Test_Test001 : System.Web.UI.Page
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connectionString"]);
    public string sql;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {  
            //页面数据绑定
            BindData("jobno");
        }
    }
    private void BindData(string sort)
    {
       
        sql = "select top 100 jobno,jobfixno,jobproperty,jobtype,inputdate from jobse";
        SqlDataAdapter myda = new SqlDataAdapter(sql, conn);
        conn.Open();
        DataSet ds = new DataSet();
        myda.Fill(ds, "RusTable");
        DataView dv = ds.Tables["RusTable"].DefaultView;
        if (sort == "")
        {
            dv.Sort = " jobno Desc";
        }
        else
        {
            dv.Sort = sort + " Desc";
        }
        GridView1.DataSource = dv;
        GridView1.DataBind();
        conn.Close();
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        BindData(ViewState["SortEx"].ToString());
    }
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        ViewState["SortEx"] = e.SortExpression;
        BindData(e.SortExpression);

    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:44733次
    • 积分:650
    • 等级:
    • 排名:千里之外
    • 原创:19篇
    • 转载:0篇
    • 译文:0篇
    • 评论:11条
    文章分类