Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Saturday, August 15, 2009

Creating a Pageable Gridview with Customized Pager Buttons


Matt Berseth put together a great post on creating a pageable GridView. It is basically a custom control that inherits from GridView and implements the DataPageable interface. The coolest part is how the GridView CSS is tailored to a specific looking type of Gridview.

I think it is worth going one step further and tailoring the DataPager with custom images to indicate both enabled and disabled. You will notice that there is a FirstPageImageUrl in the NextPreviousPagerField but no available FirstPage_DisabledImageUrl. To overcome this, we need to examine the DataPager controls dynamically and switch the images according to whether we are already at the start index or last index. This code is placed in the GridView's DataBound event:

protected void gvProducts_DataBound(object sender, EventArgs e)
{
ImageButton ibtn;
int pgEnd = gvProducts.PageCount;
int curPg = gvProducts.PageIndex;
foreach (Control ct in pager.Controls[0].Controls)
{
if(ct.GetType().Equals(typeof(ImageButton)))
{
ibtn = ct as ImageButton;
if (0 == curPg)
{
ibtn.ImageUrl = "~/images/PageFirst_Disabled.jpg";
}
else { ibtn.ImageUrl = "~/images/PageFirst.jpg"; }
}
}
foreach (Control ct in pager.Controls[2].Controls)
{
if (ct.GetType().Equals(typeof(ImageButton)))
{
ibtn = ct as ImageButton;
if ((pgEnd-1) == curPg)
{
ibtn.ImageUrl = "~/images/PageLast_Disabled.jpg";
}
else { ibtn.ImageUrl = "~/images/PageLast.jpg"; }
}
}
}


I also changed the section in Matt's Default.aspx to:


<!-- Notice this is outside the GridView -->
<div class="pager">
<asp:DataPager ID="pager" runat="server" PageSize="8" PagedControlID="gvProducts">
<Fields>
<asp:NextPreviousPagerField
ButtonType="Image"
FirstPageImageUrl="~/images/PageFirst.jpg"
RenderDisabledButtonsAsLabels="false"
ShowFirstPageButton="true" ShowPreviousPageButton="false"
ShowLastPageButton="false" ShowNextPageButton="false"
/>
<asp:NumericPagerField
ButtonCount="7" NumericButtonCssClass="command"
CurrentPageLabelCssClass="current" NextPreviousButtonCssClass="command"
/>
<asp:NextPreviousPagerField

ButtonType="Image"
LastPageImageUrl="~/images/PageLast.jpg"
RenderDisabledButtonsAsLabels="false"
ShowFirstPageButton="false" ShowPreviousPageButton="false"
ShowLastPageButton="true" ShowNextPageButton="false"
/>
</Fields>
</asp:DataPager>
</div>


The crude Microsoft Paint images are located here: http://techron.scottrichmond.com/downloads/2210036646138181629images.zip

Now you know a technique to customize the DataPager. I further customized the buttons to display custom buttons (print, search, etc.) in the center and pager buttons on the right using JavaScript. That involves a lot of screen calculation details and JavaScript that is another topic. Note, the customization comes at a performance cost. This can be improved with direct reference to the control[x].FindControl("myImgControl"), but that requires inspecting how .NET names the ImageButton in the Debugger.

The result is customized ImageButtons for enabled and disabled buttons.

Download/view Matt's code to add in the customization I've written about.

References:

12 comments:

andy said...

In today’s internet savvy world an online presence is a must for any organization weather big or small, but just a mere website of the company wont serve the purpose of reaching out and impressing the target audience, your online presence should leave an impact on the mind of the viewers, and from here comes website designing and development companies of Delhi, search engine optimization and marketing companies of Delhi and internet marketing services providing companies of Delhi in picture. These companies provide end to end solutions for all your website related issues.

Anonymous said...

Can anyone recommend the robust Software Deployment system for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central remote desktop
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!

Anonymous said...

I have found it on this website called [url=http://tipswift.com]tip swift[/url]. You can find it there.
cheers
edit: wrong thread,

Anonymous said...

Until recently I thought earning online, or creating a home based small business as an impossible task. Lately after interacting some of the industry experts, I developed a methodology to earn continuous stream of income. The mantra is to earn money thorugh multiple streams, this will cut down on the risks involved. Do check my site, where I have listed out all free and easy money making oppotunities, check[url=http://www.earn-online-money.com]Earn Easy Online Money[/url]. Do feel free to comment about the methods, your feedback is important for me. Regards

Anonymous said...

[url=http://tinyurl.com/getvpn][b]Click here to get VPN service![/b][/url]

[b]Anonymous surfing[/b]
Using our service you'll be fully anonymous in the Internet. Hide your IP address, and nobody will know that strange visitor from Germany ( Great Britain, Estonia and so ), is you.

[b]Full access to network[/b]
You can use any services, access any sites and use any software with us. BitTorrent, Skype, Facebook, MySpace, Twitter, Pocker .. we have no restrictions.

[b]Traffic protection[/b]
Don't worry, from this moment all you data will be protected using 256 bit Blowfish encryption algorithm. Nobody can access your internet data.

[b]Wide variety of countries[/b]
You can choose one of over twenty high speed servers located in different parts of the world, from South America coast to islands in Indian Ocean.

Related keywords:
anonymous surfing review
proxy server vpn
anonymous secure surfing
proxy vpn
anonymous vpn free
internet explorer vpn
vpn dial up
ssl vpn
Traffic protection
anonymous surfing freeware
anonymous surfing software
vtunnel
anonymous surfing vpn
best anonymous browser
surf the web anonymous
best anonymous surfing
anonymizer anonymous surfing review
firefox anonymous surfing
Virtual Private Networks
Free Vpn Client Software
anonymous surfing software
[url=http://dasbmw.ru] anonymous surfing software[/url]
[url=http://seobraincenter.ru] anonymous proxy[/url]
[url=http://carlwebster.com/members/Alexander-Pwnz.aspx]Buy Cheap Zoloft[/url]

Anonymous said...

Well, If you have ever thought about writing some script to automate those things that you are doing many times each day, then you have a great and easy way to automate the entir e process. It comes without saying that a few imacros and firefox add-ons will automate all actions related to a browser (Mozilla). If you want to automate your system as such, then you'll need another script, easy commands will automate your system. Even a beginner will automate things using a simple software called as sikuli all you need to do is to inform Sikuli what to do by giving some screenshots and simple commands.
A GUI will be used with Sikuli. Sikuli is an open siurce scripting application that will use a mix of easy commands like click, type, wait and so on. There's no internal API support, it just searches the screen for the image in the screenshot-that implies that you'll use it for anything. There is literally no limit on how you employ it to automate things.
This is too good to be true, but if you watch the following video, you will come to know that this is often very easy. If you visit their home page, you get a lot of tutorials and support; it can be a cake walk even for beginners. You can check the video as well as get the software at [url=http://technoages.com/operating-system/apple-mac-os/automate-everything-through-a-simple-script-make-your-computer-listen-to-you/]TechnoAges.com[/url]

Anonymous said...

[url=http://tinyurl.com/getvpn][b]Click here to get VPN service![/b][/url]

[b]Anonymous surfing[/b]
Using our service you'll be fully anonymous in the Internet. Hide your IP address, and nobody will know that strange visitor from Germany ( Great Britain, Estonia and so ), is you.

[b]Full access to network[/b]
You can use any services, access any sites and use any software with us. BitTorrent, Skype, Facebook, MySpace, Twitter, Pocker .. we have no restrictions.

[b]Traffic protection[/b]
Don't worry, from this moment all you data will be protected using 256 bit Blowfish encryption algorithm. Nobody can access your internet data.

[b]Wide variety of countries[/b]
You can choose one of over twenty high speed servers located in different parts of the world, from South America coast to islands in Indian Ocean.

Related keywords:
anonymous surfing review
proxy server vpn
anonymous secure surfing
proxy vpn
anonymous vpn free
internet explorer vpn
vpn dial up
ssl vpn
Traffic protection
anonymous surfing freeware
anonymous surfing software
vtunnel
anonymous surfing vpn
best anonymous browser
surf the web anonymous
best anonymous surfing
anonymizer anonymous surfing review
firefox anonymous surfing
Virtual Private Networks
Free Vpn Client Software
anonymous surfing software
[url=http://dasbmw.ru] anonymous surfing software[/url]
[url=http://seobraincenter.ru] anonymous proxy[/url]
[url=http://carlwebster.com/members/Alexander-Pwnz.aspx]Buy Cheap Zoloft[/url]

Anonymous said...

Hello,

can anyone tell me which is the best counter strike guide ? :)...i found this one :

http://www.downloadzdb.com/Counter_Strike_Best_Guide

What do you upon up with wits it ?

Thanx in advance

Sorry for my bad english :s

braxton said...

Earning money online never been this easy and transparent. You would find great tips on how to make that dream amount every month. So go ahead and click here for more details and open floodgates to your online income. All the best.

Anonymous said...

hiya


just found your site and wanted to ask for some advice on marketing


hopefully this is just what im looking for, looks like i have a lot to read Im trying to find a way to build an e-mail list.

Anonymous said...

Internet Assist is a leading web design and web development company based in Essex and London, who specialise in website design, hosting and marketing solutions for small, medium and large organisations. We are at your service for any of your web design needs. Visit http://www.i-a.co.uk.

Anonymous said...

[url=http://www.001casino.com/]online casinos[/url] collar not on the reborn casino games at this all stylish [url=http://www.playatonlinecasinos.com/]online casino games[/url] be at the helm with at open-handed [url=http://www.playatonlinecasinos.com/]casino[/url] gratuity and [url=http://www.playatonlinecasinos.com/casino-games.html]casino games[/url] like slots, roulette, blackjack and more [url=http://www.playatonlinecasinos.com/]online csinos[/url] games.. at this [url=http://www.playatonlinecasinos.com/]aussie casino[/url].

Blog Archive