在asp.net中对Session数据集进行排序 [英] sort a Session dataset in asp.net

查看:63
本文介绍了在asp.net中对Session数据集进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个会话数据集,我绑定到转发器控件。我希望这些值以递增的顺序显示在转发器中。我试图对数据集进行日期排序,但它对我不起作用。



这是我的代码

Hi,

I have a session dataset which I am binding to a repeater control. I would like the values to be shown in the repeater in ascending order. I am trying to sort the dataset date wise but it is not working for me.

Here is my code

DataSet dsAut = (DataSet)Session["dsAuto"];
dsAut.Tables[0].Select("","ShipDateOrignal ASC");

if (dsAut != null && dsAut.Tables[0].Rows.Count > 0)
{
                    rptCart.DataSource = dsAut;
                    rptCart.DataBind();
}





绑定数据集但未实施ASC订单。



有什么建议吗?



It binds the dataset but is not implementing the ASC order.

Any suggestions?

推荐答案

您可以使用以下方法。



You can use following method.

dsAut.Tables[0].DefaultView.Sort = "ShipDateOrignal ASC";
if (dsAut != null && dsAut.Tables[0].Rows.Count > 0)
{
        rptCart.DataSource = dsAut.DefaultView.ToTable();
        rptCart.DataBind();
}


上面的代码没有给出任何例外,但仍然数据绑定到未按ShipDateOrignal排序的转发器......



任何建议????



谢谢,



Asfand
Above codes are not giving any exceptions but still the data bind to repeater not sorted by ShipDateOrignal...

Any suggestion????

Thanks,

Asfand


您好,使用上面的一个代码,但您必须对代码进行微小的更改,请再使用一个临时数据集并将其用于新的排序。



DataSet dsTemp = new DatqSet();



dsAut.Tables [0] .DefaultView.Sort =ShipDateOrignal ASC;

dsTemp = dsAut.Copy();



if(dsTemp!= null && dsTemp.Tables [0] .Rows.Count> 0 )

{

rptCart.DataSource = dsTemp.DefaultView.ToTable();

rptCart.DataBind();

}



它应该有效,您正在对将影响新数据集的数据集进行排序。



谢谢,

Bhavin
Hi, use above one code but you have to make minor change in code that is please take one more temporary Dataset and use it for new sorting.

DataSet dsTemp = new DatqSet();

dsAut.Tables[0].DefaultView.Sort = "ShipDateOrignal ASC";
dsTemp = dsAut.Copy();

if (dsTemp != null && dsTemp.Tables[0].Rows.Count > 0)
{
rptCart.DataSource = dsTemp.DefaultView.ToTable();
rptCart.DataBind();
}

It should works as, you are applying sorting on dataset which will affecting in new dataset.

Thanks,
Bhavin


这篇关于在asp.net中对Session数据集进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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