Subscribe:

Pages

Featured Posts

May 10, 2009

ListView Pagination Error and Hiding pagination for no results

Issue 1: List View Pagination  Works only for Second click of  Page index

Description:I am using listview with datapager control. But Datapager is showing pages only when i click the page index for the second time.

Resolution: Call List view databind method in page prerender event

eg:

       protected void Page_PreRender(object sender, EventArgs e)

        {

            listLibrary.DataBind();

        }

Issue2: DatePager Control was showing 1-0 0f 0 when no records was found

Description: i was using Data pager control outside the listview control so it was visible even when there were no records in listview.

Resolution : I moved the DataPager inside the Listview Layout Template and Added EmptyDataTemplate with msg ‘no records found’ text.

February 20, 2008

GridView Pagination Template

Here is C# code to display gridview Pagination in the form
'1 2 3 4 5 6 7 Records 1 - 20 of 132 '

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
// Use the RowType property to determine whether the
// row being created is the Pager row.
//count is total no of records
if (e.Row.RowType == DataControlRowType.Pager){
Label total = new Label();
total.Text = "Records " + (GridView1.PageIndex == 0 ? 1 : ((GridView1.PageIndex) * 10) + 1).ToString() + " - " + (GridView1.PageIndex == (count / 10) ? count : ((GridView1.PageIndex + 1) * 10)).ToString() + " of " + count.ToString();
total.Font.Bold = true;
TableCell tot = new TableCell();
tot.Controls.Add(total);
tot.Attributes["width"] = "100%";
tot.Attributes["align"] = "right";
Table dtemp = (Table)e.Row.Cells[0].Controls[0];
dtemp.Rows[0].Cells.Add(tot);
}
}