add link to existing Gridview 2.0 default pagertemplate

G

Guest

When I try and edit the PagerTemplate it erases the default paging controls.
Is there a way to add a link control to this region while still keeping the
default paging controls?

Thanks.
 
G

Guest

If you are looking to add a static control (that does not need to raise a
server-side event) then consume the RowCreated event instead of overwritting
the PagerTemplate, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
HyperLink hlink= new HyperLink();
hlink.NavigateUrl="AnotherPage.aspx";
hlink.Text="PageTitle";
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(hlink);
}
}
 
G

Guest

Wow! perfectomundo! do you sometimes feel you know TOO much?

Thanks.

Phillip Williams said:
If you are looking to add a static control (that does not need to raise a
server-side event) then consume the RowCreated event instead of overwritting
the PagerTemplate, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
HyperLink hlink= new HyperLink();
hlink.NavigateUrl="AnotherPage.aspx";
hlink.Text="PageTitle";
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(hlink);
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Dabbler said:
When I try and edit the PagerTemplate it erases the default paging controls.
Is there a way to add a link control to this region while still keeping the
default paging controls?

Thanks.
 
G

Guest

This didn't work for me, nothing appears in the HTML. I also tried:

protected void VanListGridView_PreRender( object sender, EventArgs e ) {
GridView grid = ( sender as GridView );

if ( grid != null ) {
GridViewRow pagerRow = grid.BottomPagerRow;

if ( pagerRow != null && pagerRow.Visible ) {
Table pagerTable = ( pagerRow.Cells[0].Controls[0] as Table );
HyperLink hlink = new HyperLink();
hlink.NavigateUrl = "VanListDetail.aspx";
hlink.Text = "New...";
hlink.CssClass = "waLink";
//pagerRow.Cells[0].Controls.AddAt( 0, hlink );
pagerRow.Cells[0].Controls.Add( hlink );

}
}
}

which also did nothing. I would be willing to use a PagerTemplate but would
like to keep the automagic page numbers links that are generated by the
GridView.

Any suggestions?

Phillip Williams said:
If you are looking to add a static control (that does not need to raise a
server-side event) then consume the RowCreated event instead of overwritting
the PagerTemplate, e.g.

void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.Pager)
{
HyperLink hlink= new HyperLink();
hlink.NavigateUrl="AnotherPage.aspx";
hlink.Text="PageTitle";
//notice that the pager template renders one cell in which
//there is an HTMLTable
e.Row.Cells[0].Controls.Add(hlink);
}
}
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Dabbler said:
When I try and edit the PagerTemplate it erases the default paging controls.
Is there a way to add a link control to this region while still keeping the
default paging controls?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top