Possible to do Custom Formatting on Gridview

R

RCM

I have a very simple gridview that is working fine. My real data is
more complicated, but for purposes of my question imagine a grid
display that looks like:

Audi red heavy
Audi blue medium
Audi green medium
Ford red medium
Ford green light
Volks red heavy
Volks red light
Volks yellow heavy

Now, suppose I want to start customizing things. For example, the
first column is actually not editable, so I don't want to see
repeating values and I want the grid to look like:

Audi red heavy
blue medium
green medium
Ford red medium
green light
Volks red heavy
red light
yellow heavy

Or perhaps I just want the auto make to be listed as a subheader row
on its own, as in

Audi
red heavy
blue medium
green medium
Ford
red medium
green light
Volks
red heavy
red light
yellow heavy

And so on and so on - there are obviously all sorts of customizations
one might want to do.

I am having trouble figuring out what is the right/best way to do
these sorts of things. For example, in the first case I described,
where repeating values are to be eliminated, I could certainly go in
and programmatically modify the data to which the grid is bound before
it is bound, but that seems crazy.

And I'm not even sure how the 2nd example would be done. Is there some
event I can hook into when the actual HTML for the grid is being
generated? I don't see anything, but perhaps I am missing it.

Are nested grid views the right answer? Seems like overkill to me, but
maybe that is the way to do it.

Any examples or pointers to good articles with tips on this sort of
gridview customization would be greatly appreciated.

Thanks in advance!
 
E

Eliyahu Goldin

This is what the PreRender event for. Populate the grid with all possible
values, like in you first example, and then, in the PreRender event, loop
through the items and hide fields that you don' want to show. This will make
your second example. To come to the third example, you will need to make an
item template containing a table with 2 rows. The model name will go to the
first row and other parameters to the second. In the PreRender event you
will detect the very first item for the model and leave it's first row
visible. Than you will hide the first row for all other items of the same
model.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
R

RCM

Thanks! - those suggestions got me going in the right direction. In
particular, I didn't even know about templates. That's what I ended up
using.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top