»Dotnet Ads
»Message Boards
Message Boards
Dotnet Books
»Member Details
Register
Login
LogOut
Submit Code
Submit Jobs
Submit Projects
»Competition
Community
Winners
Prizes
Write For Us
Members
»Other Resources
Links
Dotnet Resources
|
Adding sorting to a datagrid in ASP.NET and C#This small piece of code shows how to add sorting in a datagrid in asp.net c#
the earlier one we have on this site is in vb.net
private void dgSearch_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
string[] arrSort;
arrSort = lblSort.Text.Split(' ');
if (e.SortExpression == arrSort[0])
{
if (arrSort[1] == "ASC")
{
lblSort.Text = e.SortExpression + " DESC";
}
else
{
lblSort.Text = e.SortExpression + " ASC";
}
}
else
{
lblSort.Text = e.SortExpression + " ASC";
}
dgSearch.EditItemIndex = -1;
SortGrid();
}
private void SortGrid()
{
db.ResetParams();
DataTable dt = db.RetrieveDataTableFromSelect("query");
DataView dv = new DataView(dt);
dv.Sort = this.lblSort.Text;
dgSearch.DataSource = dv;
dgSearch.DataBind();
} |
|