Friday 21 October 2011

Solution for Pageindex error on datagrid bind

if (DT.Rows.Count > 0)
               {
                   try
                   {
                       DataView dvCompanyName = new DataView(DT);
                       grdProductList.DataSource = dvCompanyName;
                       grdProductList.DataBind();
                   }
                   catch (Exception ex)
                   {
                       if (!(grdProductList.CurrentPageIndex < grdProductList.PageCount))
                       {
                           if (!(grdProductList.PageCount == 0))
                           {
                               grdProductList.CurrentPageIndex = grdProductList.PageCount - 1;
                               grdProductList.DataBind();
                           }
                       }
                       else
                       {
                           grdProductList.DataBind();
                       }
                   }
               }