Click here to Skip to main content
15,906,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how we will do pagging and sorting in dynamic created gridview using c#?
Posted

you use PageIndexChanging Event of Grid .
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
         GridView1.PageIndex = e.NewPageIndex;
         // bind grid using Select Query.
}

hope this will help you, if not please post it.
 
Share this answer
 
Comments
Member 9208931 5-Jul-12 1:08am    
this is working thanks for the solution but another question i want to say that how we will do columns sorting in dynamic griedview?
Ok , My dear Friends, Just in Gridview Properties set allow sorting=true

then write this code.

C#
private string ConvertSortDirectionToSql(SortDirection sortDirection)
    {
        string newSortDirection = String.Empty;

        switch (sortDirection)
        {
            case SortDirection.Ascending:
                newSortDirection = "ASC";
                break;

            case SortDirection.Descending:
                newSortDirection = "DESC";
                break;
        }

        return newSortDirection;
    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        DataTable dataTable = GridView1.DataSource as DataTable;

        if (dataTable != null)
        {
            DataView dataView = new DataView(dataTable);
            dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

            GridView1.DataSource = dataView;
            GridView1.DataBind();
        }
    }



ok, this will be definitely help u.
 
Share this answer
 
v2
Comments
Member 9208931 5-Jul-12 8:46am    
this is nice and work correctly

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900