M
marty
Having trouble creating a dynamic pagertemplate. I want it like this
"Prev 1 2 3 4 Next". The numerically portion being the dynamic part
based on the record count.
I can generate it, but can't get any events to fire.
Is it possible to do? I've tried creating them int he RowCreated
event, DataBound and my own PagerTemplate, but nothing seems to work.
Here is one snippet that I've tried. It causes a postback, but it
isn't handled by the gridview.
protected void gvSearchResults_RowCreated(object sender,
GridViewRowEventArgs e)
{
if( e.Row.RowType == DataControlRowType.Pager)
{
// Get the pager row.
GridViewRow pagerRow = e.Row;
// Get the pager row.
Panel pagesPanel =
(Panel)pagerRow.FindControl("PagesPanel");
//Panel pagesPanel = pagesPanel;
LinkButton myButton = new LinkButton();
myButton.Text = "Prev";
myButton.CommandName = "Page";
myButton.CommandArgument = "Prev";
myButton.ID = "PrevPage";
pagesPanel.Controls.Add(myButton);
for (int i = 1; i < ((GridView)sender).PageCount + 1; i++)
{
myButton = new LinkButton();
myButton.Text = String.Format("{0} ", i);
myButton.CommandName = "Page";
myButton.CommandArgument = i.ToString();
myButton.ID = "Page" + i;
pagesPanel.Controls.Add(myButton);
}
myButton = new LinkButton();
myButton.Text = "Next";
myButton.CommandName = "Page";
myButton.CommandArgument = "Next";
myButton.ID = "NextPage";
pagesPanel.Controls.Add(myButton);
}
}
"Prev 1 2 3 4 Next". The numerically portion being the dynamic part
based on the record count.
I can generate it, but can't get any events to fire.
Is it possible to do? I've tried creating them int he RowCreated
event, DataBound and my own PagerTemplate, but nothing seems to work.
Here is one snippet that I've tried. It causes a postback, but it
isn't handled by the gridview.
protected void gvSearchResults_RowCreated(object sender,
GridViewRowEventArgs e)
{
if( e.Row.RowType == DataControlRowType.Pager)
{
// Get the pager row.
GridViewRow pagerRow = e.Row;
// Get the pager row.
Panel pagesPanel =
(Panel)pagerRow.FindControl("PagesPanel");
//Panel pagesPanel = pagesPanel;
LinkButton myButton = new LinkButton();
myButton.Text = "Prev";
myButton.CommandName = "Page";
myButton.CommandArgument = "Prev";
myButton.ID = "PrevPage";
pagesPanel.Controls.Add(myButton);
for (int i = 1; i < ((GridView)sender).PageCount + 1; i++)
{
myButton = new LinkButton();
myButton.Text = String.Format("{0} ", i);
myButton.CommandName = "Page";
myButton.CommandArgument = i.ToString();
myButton.ID = "Page" + i;
pagesPanel.Controls.Add(myButton);
}
myButton = new LinkButton();
myButton.Text = "Next";
myButton.CommandName = "Page";
myButton.CommandArgument = "Next";
myButton.ID = "NextPage";
pagesPanel.Controls.Add(myButton);
}
}