Hí, how I do integrate this class in my webappl.
I have created the class in App_Code dir. In the aspx Page I made this <%@ Register TagPrefix="Custom" Namespace="BbackGridView" %> but I got this error:
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Unknown server tag 'BbackGridView:PageGridView1'.
Source Error:
Line 198: <td style='padding-top:0px; padding-left:19px; padding-bottom:20px'>
Line 199:
Line 200:<BbackGridView:PageGridView1 DataKeyNames="BbackCode" ID="BBACK" AutoGenerateColumns="False"
Line 201: OnRowCommand="BBACK_RowCommand" OnRowDataBound="BBACK_RowDataBound" DataKeyField="BbackCode"
Line 202: Width="501" GridLines="None" BackColor="#ffffff" CellSpacing="2" |
This is the namespace:
namespace BbackGridView
{
public class PageGridView1 : GridView
{
public PageGridView1()
{
InitializeGridGomponent();
}
private void InitializeGridGomponent()
{
EnableViewState = false;
AutoGenerateColumns = false;
BorderWidth = 0;
CellSpacing = 1;
CellPadding = 0;
// Paging and Sorting
AllowPaging = true;
AllowSorting = true;
GridLines = GridLines.None;
//Pager Setting
PagerStyle.Width = Unit.Percentage(100);
PagerStyle.HorizontalAlign = HorizontalAlign.Right;
PagerStyle.VerticalAlign = VerticalAlign.Middle;
PagerSettings.Position = PagerPosition.TopAndBottom;
PagerSettings.Mode = PagerButtons.NextPreviousFirstLast;
PagerSettings.NextPageText = "Goto next page";
PagerSettings.PreviousPageText = "Goto previous page";
PagerSettings.FirstPageText = "Goto first page";
PagerSettings.LastPageText = "Goto last page";
RowCreated += new GridViewRowEventHandler(OnRowCreated);
}
void OnRowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Pager)
{
CustomizePageBar(e);
}
}
private void CustomizePageBar(GridViewRowEventArgs e)
{
Table tblPager = new Table();
tblPager.BorderWidth = 0;
tblPager.CellPadding = 0;
tblPager.CellSpacing = 0;
tblPager.Width = Unit.Percentage(100);
tblPager.Height = Unit.Pixel(20);
//add a row for our pager contents
tblPager.Rows.Add(new TableRow());
//Spacer Cell
TableCell tcelSpace = new TableCell();
tcelSpace.Width = Unit.Pixel(360);
//Page x of y Cell
TableCell tcelXofY = new TableCell();
tcelXofY.Width = Unit.Pixel(100);
Label litXofY = new Label();
litXofY.Text = "Page " + (this.PageIndex + 1) + " of " + this.PageCount;
litXofY.Font.Bold = true;
tcelXofY.Controls.Add(litXofY);
//lable GoTo
Label lblGoto = new Label();
lblGoto.Text = "GoTo: ";
lblGoto.ID = "lblGoTo";
lblGoto.Font.Bold = true;
lblGoto.Font.Size = this.PagerStyle.Font.Size;
TableCell tcelGoto = new TableCell();
tcelGoto.Width = Unit.Pixel(25);
tcelGoto.Controls.Add(lblGoto);
//Pick drop downlist
TableCell tcelPickPage = new TableCell();
tcelPickPage.Width = Unit.Pixel(25);
//The dropdown list box
DropDownList ddlPickPage = new DropDownList();
ddlPickPage.ID = "ddlPick";
ddlPickPage.AutoPostBack = true;
ddlPickPage.EnableViewState = true;
ddlPickPage.Font.Size = this.PagerStyle.Font.Size;
for (int index = 1; index <= this.PageCount; index++)
{
ddlPickPage.Items.Add(index.ToString());
}
ddlPickPage.SelectedIndex = this.PageIndex;
//handle event for picklist
ddlPickPage.SelectedIndexChanged += new EventHandler(OnPagePicked);
tcelPickPage.Controls.Add(ddlPickPage);
//The existing Nav controls
TableCell tcelNav = new TableCell();
tcelNav.Width = Unit.Pixel(150);
//for move all existing controls
foreach (Control ctrl in e.Row.Cells[0].Controls)
{
tcelNav.Controls.Add(ctrl);
}
// add all cells to new pager
tblPager.Rows[0].Cells.Add(tcelSpace);
tblPager.Rows[0].Cells.Add(tcelXofY);
tblPager.Rows[0].Cells.Add(tcelGoto);
tblPager.Rows[0].Cells.Add(tcelPickPage);
tblPager.Rows[0].Cells.Add(tcelNav);
//replace grids pager with new
e.Row.Cells[0].Controls.Add(tblPager);
//EmbeddResources();
}
protected void OnPagePicked(object sender, EventArgs e)
{
DropDownList ddlPick = (DropDownList)sender;
this.PageIndex = Convert.ToInt32(ddlPick.SelectedItem.Value) - 1;
//Raise page index changed so user can rebind data
GridViewPageEventArgs gvArgs = new GridViewPageEventArgs(Convert.ToInt32 (ddlPick.SelectedItem.Value) - 1);
OnPageIndexChanging(gvArgs);
}
}
}
Please help me to integrate this custom Gridviewpager in my aspx Page.
Thanks a lot in advance
Andreas