Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

Blog Directory
Blogging Fusion Blog Directory
Web Directory
Blog Directory
EatonWeb Blog Directory
GeekySpeaky: Submit Your Site!
Blog Directory
blogarama - the blog directory
Bloglisting.net - The internets fastest growing blog directory
Blogio.net blog directory
Free Blog Directory
blog search directory
Software Blogs
RSSMicro FeedRank Results
On our way to 1,000,000 rss feeds - millionrss.com
Listed in LS Blogs the Blog Directory and Blog Search Engine
blog directory
Link With Us - Web Directory
Web Blogs Directory Add Your Blog.com

Certificates

Links

Social

GridView and Invalid CurrentPageIndex Value Exception - .Net 3.5 Version

In my previous GridView entry titled as GridView and Invalid CurrentPageIndex Value Exception I made an example about how to corrigate paged GridView page index before grid is bound to data. Let's to id now .Net Framework 3.5 way.


public static class GridViewExtensions
{ 
    public static void CorrigatePageIndex(this GridView gdv, Int32 rowCount)
    {
        Int32 newIndex = gdv.PageIndex;
        if(gdv.PageSize> 0) 
            if((Int32)Math.Ceiling((decimal)rowCount / gdv.PageSize) < newIndex)
                newIndex = (Int32)Math.Ceiling((decimal)rowCount / gdv.PageSize); 
        if(newIndex <0) 
            newIndex = 0;
        gdv.PageIndex = newIndex;
    }
}

Now we can corrigate page index usng the following code.


protected void Page_Load(object sender, EventArgs e)
{
    if (this.IsPostBack)
        return;
    DataTable dt = GetRows();
    gdvList.PageIndex = 15;
    gdvList.DataSource = dt;
    gdvList.CorrectCurrentPage(dt.Rows.Count);
    gdvList.DataBind();
}

Posted: Jun 12 2008, 09:12 AM by DigiMortal | with no comments
Filed under: ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)