By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,296 Members | 1,475 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,296 IT Pros & Developers. It's quick & easy.

add link to existing Gridview 2.0 default pagertemplate

P: n/a
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.
Mar 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" wrote:
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.

Mar 20 '06 #2

P: n/a
Wow! perfectomundo! do you sometimes feel you know TOO much?

Thanks.

"Phillip Williams" wrote:
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" wrote:
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.

Mar 20 '06 #3

P: n/a
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" wrote:
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" wrote:
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.

Mar 28 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.