Home > Forum > ASP.NET > How to display records of gridview?

How to display records of gridview?

by Thamil   on Sep 30, 2013   Category: ASP.NET  |  Views: 1601    |  Points: 5   |  Gold 
  Reply
Dear All,

I have one gridview. In this grid view I want display total records. I wrote code in this code I am gettin error.


this is my code
GridViewRow disprecod = gvCatOfPersons.BottomPagerRow
DataView view
if (disprecod == null) return
Label lblPageCount = (Label)disprecod.Cells[0].FindControl("lblPageCount")
if (lblPageCount != null)
{

//DataTable dt = ((DataView)gvCatOfPersons.DataSource).Table
int iTotalRecords = ((DataTable)(gvCatOfPersons.DataSource)).Rows.Count
//int iTotalRecords = dt.Rows.Count
int iEndRecord = gvCatOfPersons.PageSize * (gvCatOfPersons.PageIndex + 1)
int iStartsRecods = iEndRecord - gvCatOfPersons.PageSize // I am getting eorr hear unable to cast object of type system.data.dataview to type system.data.datatable

if (iEndRecord > iTotalRecords)
{
iEndRecord = iTotalRecords
}

if (iStartsRecods == 0)
{
iStartsRecods = 1
}
if (iEndRecord == 0)
{
iEndRecord = iTotalRecords
}
lblPageCount.Text = "Display " + " " + iStartsRecods + " - " + iEndRecord.ToString() + " of " + iTotalRecords.ToString()
}

question posted on behalf of shaik .


Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 
  Re :How to display records of gridview?   
by Thamil
on Sep 30 2013 12:33PM
Points : 10
Gold 
hello shaik,

This is simplay and easy. take the total no.of records from dataset or table as like below.

GridViewSample.DataSource = ds.Tables[0];
GridViewSample.DataBind();
lblTotalRecords.Text = "Total records: " + ds.Tables[0].Rows.Count;

Recent Post

Latest Posts