如何使用数据表或数据集在数据库中保存排序列? [英] How to save sort column in database using data table or dataset ?
本文介绍了如何使用数据表或数据集在数据库中保存排序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用数据表或数据集在数据库中保存排序列?
我有一个包含Id,Name和Age列的三列表。
How to save sort column in database using data table or dataset ?
I have a three column table containing Id, Name and Age columns.
Id Name Age
1 Aditya 25
2 Raj 20
3 Mohan 15
protected void Page_Load(object sender, EventArgs e)
{
string CS = ConfigurationManager.ConnectionStrings["OnlineEducationSystemConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(CS);
SqlDataAdapter adap = new SqlDataAdapter("select * from Test", con);
DataTable dt = new DataTable();
adap.Fill(dt);
dt.DefaultView.Sort = "Id, Name ASC";
GridView1.DataSource = dt;
GridView1.DataBind();
}
请建议。
Please suggest.
推荐答案
你可以使用 GridView.Sort方法( String,SortDirection)(System.Web.UI.WebControls) [ ^ ]使用GridView控件对数据进行排序。
如果出于某种原因想要使用数据表进行排序,可以使用 DataView.Sort属性(System.Data) [ ^ ]。
You can use the GridView.Sort Method (String, SortDirection) (System.Web.UI.WebControls)[^] to sort the data using the GridView control.
If for some reason you want to do the sorting with the data table, you can use the DataView.Sort Property (System.Data)[^].
这篇关于如何使用数据表或数据集在数据库中保存排序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文