如何使我的网格视图中的标题能够排序? [英] How to make the Header in my grid view able to sort?

查看:75
本文介绍了如何使我的网格视图中的标题能够排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我在网上看过很多关于我的问题的文章。每当我点击标题时,我想按降序对记录进行排序。但我仍然想知道其他一些条款,有时我不理解我发现的文章。谁能帮我吗?在此先感谢!

解决方案

亲爱的DarkDreamer08,





请,以下步骤启用gridview进行排序启用。



1.选择GRIDVIEW并转到属性窗口选择 AllowSorting 使其成为 True



以上非常一般的gridview排序方式。



之后运行你的应用程序检查它。



如果直接附加 SQLDatasource 然后它的确定,其他类型的数据源,那么你必须检查它进行更严格的处理。< br $>


为了更好的事情告诉我你的代码。

Manoj Kalla。


// --- ---用于分类里程碑的数据库

私有DataView Getdata()

{

connection();

amicassaCon .Open();

DataSet dsMilestone = new DataSet();

string strSelectCmd =SELECT * FROM milestone;

SqlDataAdapter da = new SqlDataAdapter(strSelectCmd,amicassaCon);

da.Fill(dsMilestone,milestone);

DataView dvMilestone = dsMilestone.Tables [milestone]。DefaultView;

dvMilestone.Sort = ViewState [SortExpr]。ToString();

返回dvMilestone;



}



页面加载代码



ViewState [SortExpr] = Sort_Direction;

DataView dvMiles = Getdata();

GridView_milestone.DataSource = dvMiles;

GridView_milestone.DataBind();





  / /   ---------------排序里程碑 
protected void 排序( object sende r,GridViewSortEventArgs e)
{
string [] SortOrder = ViewState [ SortExpr]。ToString()。Split(' ' );
if (SortOrder [ 0 ] == e.SortExpression)
{
if (SortOrder [ 1 ] == ASC
{
ViewState [ SortExpr] = e.SortExpression + + DESC;
}
else
{
ViewState [ SortExpr] = e.SortExpression + + ASC;
}
}
else
{
ViewState [ SortExpr] = e.SortExpression + + ASC;
}
GridView_milestone.DataSource = Getdata();
GridView_milestone.DataBind();
}





然后允许排序到网格视图并在每个标题中包含SortExpression =FIELDNAME:)


Hi guys!

I have read lots of articles in the net regarding my question. I would like to sort my records in descending order whenever I click the Header. But I am still wondering on some other terms and sometimes I do not understand in the articles that I found. Can anyone help me out? Thanks in advance!

解决方案

Dear DarkDreamer08,


Please, following step to enable your gridview for sorting enable.

1. Select GRIDVIEW and go to property window select AllowSorting make it True

above very general kind of enabling sorting of gridview.

After that run your application check it.

If directly attached SQLDatasource then its ok, other kind of datasource then you have to check it for fruther treatment.

For fruther thing show me your code.
Manoj Kalla.


//------ DATAVIEW FOR SORTING MILESTONE
private DataView Getdata()
{
connection();
amicassaCon.Open();
DataSet dsMilestone = new DataSet();
string strSelectCmd = "SELECT * FROM milestone ";
SqlDataAdapter da = new SqlDataAdapter(strSelectCmd, amicassaCon);
da.Fill(dsMilestone, "milestone");
DataView dvMilestone = dsMilestone.Tables["milestone"].DefaultView;
dvMilestone.Sort = ViewState["SortExpr"].ToString();
return dvMilestone;

}

CODE AT PAGE LOAD

ViewState["SortExpr"] = Sort_Direction;
DataView dvMiles = Getdata();
GridView_milestone.DataSource = dvMiles;
GridView_milestone.DataBind();


//---------------SORTING MILESTONE
   protected void Sorting(object sender, GridViewSortEventArgs e)
   {
       string[] SortOrder = ViewState["SortExpr"].ToString().Split(' ');
       if (SortOrder[0] == e.SortExpression)
       {
           if (SortOrder[1] == "ASC")
           {
               ViewState["SortExpr"] = e.SortExpression + " " + "DESC";
           }
           else
           {
               ViewState["SortExpr"] = e.SortExpression + " " + "ASC";
           }
       }
       else
       {
           ViewState["SortExpr"] = e.SortExpression + " " + "ASC";
       }
       GridView_milestone.DataSource = Getdata();
       GridView_milestone.DataBind();
   }



Then allow sorting to the grid view and include the SortExpression="FIELDNAME" to each header :)


这篇关于如何使我的网格视图中的标题能够排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆