|
|
 |
BOOK: Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages ISBN: 978-0-470-12448-2
 | This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages by Jacob J. Sanford; ISBN: 9780470124482 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages ISBN: 978-0-470-12448-2 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

April 24th, 2008, 03:22 PM
|
|
Registered User
|
|
Join Date: Apr 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Customize column in CSS friendly GridView
Greetings,
I'm new to CSS, ASP.NET, and CSS friendly controls, but I feel I'm making progress with the help of Jacob Sanford's book - "Profession ASP.NET 2.0 Design..." (thanks Jacob, if you're here).
I'm currently in chapter 5 ("ASP.NET 2.0 CSS Friendly Control Adapters"). I'm experimenting with a very simple CSS friendly GridView control. Overall it's going well, but I'm wondering how I might single out a single column for non-default alignment. For example, I might want the first column to be center-aligned, while leaving the others at the default left-alignment state.
I tried specifying an ID selector down in the asp:boundfield statement, but of course it didn't like that. What am I missing?
Thanks,
Frank
|

April 24th, 2008, 04:47 PM
|
|
Wrox Author
|
|
Join Date: Sep 2006
Location: Tallahassee, FL, USA.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hey Frank-
Let me just say that the chapter you are reading was probably my favorite to write. I continue to preach the merits of the adapters to all that will listen. I am co-authoring another book on SharePoint design and I just finished writing the chapter on how to integrate the adapters inside SharePoint. I sincerely believe these to be some of the coolest enhancements out there.
Now, back to your question. What you are trying to do is, in my opinion, exactly the kind of things that you should be trying to do in the adapters. Make them work the way you want them to.
Now I have never tried to do what you are suggesting so I am just thinking out loud here. But here is what I think.
In the GridViewAdaptar.cs class file, there is a section called WriteRows(). The basic structure is:
foreach(Gridiew row in rows)
do some stuff, then:
foreach(TableCell cell in row.Cells)
do some more stuff
does that make sense?
so, before the first foreach, i would declare an INT variable, say intColumn, and intantiate it to zero.
then, in the first foreach loop, i would set it to zero again.
then, in the second foreach loop, i increment the variable by 1 for each cell.
something (this is very basic) like this:
int intColumn = 0;
foreach(GridViewRow row in rows)
{
intColumn = 0;
foreach(TableCell cell in row.Cells)
{
intColumn++;
}
}
this way, you have access to what column you are on (well, zero-based anyway)
at the end of the second foreach loop, there is a command that looks like this:
cell.CssClass += field.ItemStyle.CssClass;
so, right after that, but before you increment your variable, you might want to insert something like:
if(intColumn = 0)
{
cell.HorizontalAlign = HorizontalAlign.Center;
}
so what would happen is that your counter would reset itself with each row (which is why you are setting it to zero in the first loop). then, in your second loop, you are incrementing your counter with each column so that you can determine which column you are in. then, finally, when you are on the right column, you are setting the horizontal alignment of just that cell.
this is all theoretical, of course, so i would love to hear if this works for you. and, if not, how it breaks. this is fun for me. :D
-jacob
01000111
01000101
01000101
01001011
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |