p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional ASP.NET 2.0 Design: CSS, Themes, and Master Pages ISBN: 978-0-470-12448-2 (http://p2p.wrox.com/forumdisplay.php?f=349)
-   -   Customize column in CSS friendly GridView (http://p2p.wrox.com/showthread.php?t=67651)

Frankster April 24th, 2008 02:22 PM

Customize column in CSS friendly GridView

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?


surfer5 April 24th, 2008 03:47 PM

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)

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



elizas April 14th, 2010 10:04 AM

How to Customize the Group Text of a DevExPress Grid View
First of all you have to set gcProjectNo.GroupIndex = 0;
Then you have to handle the CustomDrawGroupRow event.

private void grdvProjectList_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDraw EventArgs e)
GridView view = sender as GridView;

DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupR owInfo info =
e.Info as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupR owInfo;

int handle = view.GetDataRowHandleByGroupRowHandle(e.RowHandle) ;

if (info.Column.FieldName == "PRJ_NO")
StringBuilder oGroupText = new StringBuilder();
oGroupText.Append(view.GetRowCellValue(handle, "PRJ_NO").ToString());
oGroupText.Append(" - ");
oGroupText.Append(view.GetRowCellValue(handle, "PRJ_NAME").ToString());

info.GroupText = oGroupText.ToString();
Hope this would be useful.Any suggestions are welcomed.

All times are GMT -4. The time now is 05:15 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.