For
GridView paging and sorting write the following code in source file of aspx
webpage:
<asp:GridView
ID="grdCause"
runat="server
EnableSortingAndPagingCallback="True"
AllowPaging="True"
AllowSorting="True"
onpageindexchanging="grdCause_PageIndexChanging"
onsorting="grdCause_Sorting"
>
</asp:GridView>
The following method is for Loading the Gridview .In this method
am taking dataset and bind that dataset to Gridview.
ExecuteProcedure is the method in my sqlhelper class.For that
method Click here.
private void LoadGrid()
{
DataSet ds = dal.ExecuteProcudere("CauseSelectAll", ht);
grdCause.DataSource = ds.Tables[0];
grdCause.DataBind();
}
Gridview pageindexChanging Event
for paging:
protected void grdCause_PageIndexChanging(object sender, GridViewPageEventArgs
e)
{
grdCause.PageIndex = e.NewPageIndex;
LoadGrid();
}
Gridview Sorting Event
for Sorting:
protected void
grdCause_Sorting(object sender, GridViewSortEventArgs e)
{
string sortExpression =
e.SortExpression;
if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
SortGridView(sortExpression,
DESCENDING);
}
else
{
GridViewSortDirection = SortDirection.Ascending;
SortGridView(sortExpression,
ASCENDING);
}
}
Use the following method for Sorting:
private void SortGridView(string
sortExpression, string direction)
{
// You
can cache the DataTable for improving performance
LoadGrid();
DataTable dt = grdCause.DataSource as DataTable;
DataView dv = new DataView(dt);
dv.Sort = sortExpression + direction;
grdCause.DataSource = dv;
grdCause.DataBind();
}
private const
string ASCENDING = "
ASC";
private const
string DESCENDING = "
DESC";
public SortDirection
GridViewSortDirection
{
get
{
if
(ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
return
(SortDirection)ViewState["sortDirection"];
}
set { ViewState["sortDirection"]
= value;
}
}
This was helpful. Thanks!
ReplyDeletethanks
Delete.Net Tutorial: Gridview Sorting And Paging In Asp.Net >>>>> Download Now
Delete>>>>> Download Full
.Net Tutorial: Gridview Sorting And Paging In Asp.Net >>>>> Download LINK
>>>>> Download Now
.Net Tutorial: Gridview Sorting And Paging In Asp.Net >>>>> Download Full
>>>>> Download LINK EN
This is awesome Thanks..
ReplyDeletethis is awesome and thanks a lot!
ReplyDeleteI get the error.
ReplyDeleteCompiler Error Message: CS0103: The name 'ht' does not exist in the current context
Help?
remove ht
ReplyDeletecareersoft-technology
This post is very useful. great work naresh. and what about my blog.
ReplyDeleteDeveloper Queries
Great stuff! There's another tutorial on this at http://www.wiseowl.co.uk/blog/s301/gridview.htm.
ReplyDeleteHi ,
ReplyDeleteCan u Please help me in I want implemented sorting in window application in c#
Thanks in advance
what is 'ht'? I removed it and it still needs an argument. help please.
ReplyDeleteGridView sorting in C# manually
ReplyDelete.Net Tutorial: Gridview Sorting And Paging In Asp.Net >>>>> Download Now
ReplyDelete>>>>> Download Full
.Net Tutorial: Gridview Sorting And Paging In Asp.Net >>>>> Download LINK
>>>>> Download Now
.Net Tutorial: Gridview Sorting And Paging In Asp.Net >>>>> Download Full
>>>>> Download LINK