Sunday, 4 November 2012

Adding Title or Caption to Gridview


Adding Title/Caption to Gridview


Have you ever wanted to add a Title or Caption to your GridView (i.e. at the top of your GridView control)?  Some of you may already be aware of the GridView.Caption property, but entering your caption text displays a simple text rather than being able to define styles like other GridView elements.  Well, I think there is a way to get around this limitation.
While trying to answer one of the post about GridView.Caption property, I realized that you can assign a full HTML rather than a simple text.  This means that you can be creative in designing what your caption looks like.  Following simple example illustrates using some HTML tags to define the border and background color to the caption area:
<asp:GridView ID="GridView1" runat="server" ...
Caption='<table border="1" width="100%" cellpadding="0" cellspacing="0" bgcolor="yellow"><tr><td>Grid Heading</td></tr></table>' CaptionAlign="Top">
What this does is to insert a Table that fills the Caption region (width="100%" ensures same width as that of the GridView) while using Yellow background color.  What's more, it opens the door to adding captions that are limited only by your imagination. 


Refer:

http://forums.asp.net/t/966407.aspx/1?How+can+I+add+Caption+Title+to+GridView+

1 comment:

  1. The width doesn't work for some reason on mine. It is displaying as a little box to the left of the gridview. Is there something I'm missing?

    ReplyDelete

Thank You for Your Comments. We will get back to you soon.

back to top