0

I have a custom pager template on one gridview that the client now wants applied to several other gridviews within the same site. It seems like extending the GridView object makes the most sense, but I'm not clear on how to create the pager template dynamically.

Any recommendations on how to accomplish this?

chprpipr
  • 2,039
  • 16
  • 17
  • Is this something you could move into a Skin that could be applied to all your GridView controls? – Zachary Jan 20 '11 at 22:56
  • I don't believe so. Its more than just styling. As the user interacts with the grid, there's is work that needs to occur in the backend to display the correct rows and update the pager display. – chprpipr Jan 20 '11 at 23:52

2 Answers2

1

Does this work:

gridview.PagerTemplate = Page.LoadTemplate("CustomPager.ascx");

http://msdn.microsoft.com/en-us/library/6d5z5yty(VS.80).aspx

UPDATE

For extension:

public class CustomGridView : GridView {
    public override void OnInit(EventArgs e) {
        base.OnInit(e);
        this.PagerTemplate = Page.LoadTemplate("CustomPager.ascx");
    }
}
djeeg
  • 6,685
  • 3
  • 25
  • 28
  • This looks very promising! I'll give it a try and let you know. – chprpipr Jan 21 '11 at 17:08
  • I decided to go with extending the GridView. In doing that, I found out that this option isn't available. This would work very well if you had a base UserControl that you wanted to extend for use in other ways within the same site. – chprpipr Jan 21 '11 at 22:36
0

I'm not sure why this article didn't turn up until now, but I found a nice tutorial on DotNetSlackers that got me going in the right direction.

http://dotnetslackers.com/articles/gridview/Custom-GridView-with-Paging-and-Filtering.aspx

Unfortunately, I did have to create the pager controls dynamically. If anyone knows a better way, I'm still all ears as I would much rather write HTML as is done in the PagerTemplate.

chprpipr
  • 2,039
  • 16
  • 17
  • A bit of a hack, but you could always create an ascx in a "library" project of type web application, precompile the app and then reference the resulting DLL. – Nelson Rothermel Dec 17 '14 at 22:29