Custom styling gridview data.

WellsCarrie

Well-known member
Joined
Jul 12, 2005
Messages
95
Location
Arkansas
Programming Experience
5-10
Ok, I know how to style the whole gridview and I know how to style a single row in the grid view, however what I need to do is style one piece of data in one field of the grid view.
For example I have a grid view that shows two sources for shipping address.
source one:
300 Any Road, Any Town, MI, 45678
Source two (same customer key):
300 Any Lane, any town, MI, 44444

First I need to format the grid field to display both addresses as two lines:
300 Any Road
Any Town, MI 45678

then I need to mark Source Two's data red where diffrent from Source One:
300 Any Lane
Any Town, MI, 44444

Aplying the font color="red" html tags around the peices I want doesn't work Nor will the grid let me add break tags to display the data.

any one have any ideas?
 
You can use the RowDataBound event to do custom formatting. Work with e.Row... For example if you place "<br>" tag in cell text here it will be multiline.

Btw, GridView control is new with .Net 2.0, should you update your forum profile?
 
Atually when I used e.row to format the display ignored it and still used the primary style for Gridviews from my style sheet. I'm certain I was doing it wrong, but in diffrence to time constraints I just plopped a "template" field into the grid so the <font> and <br> tags would work.

I'm at the point in the project plan now where "works" is good enough. Though if you could show me the code you'd use to push the formating through I'd be grateful. I'd really like to know how to do it and because of "security" settings on my workstation regarding the Internet I can no longer get to Microsoft's MSDN sites. Though strangely I can still get to "fantasy football" go figure.

As for my profile, I've been doing .net 1.1 for almost 8 years now. this is my first 2.0 application, :) but thanks for the help.
 
basically:
VB.NET:
e.Row.Cells(0).Text = "line1<br>line2"
 
Hum... ok Quick Question...
Standars of HTML calls for br tags to now be written as "< /br>" which is what I'm using. Your example only uses "<br>" is there something about the "/" that would mess up the e.row.Cells(0).text?
Because this was my original code

VB.NET:
sb.append("<font color='red'>")
sb.append(addLine1)
sb.append("</font>< /br>")
sb.append(addLine2)
sb.append("< /br>")
sb.append(city)
sb.append(", ")
sb.append(state)
sb.append(" <font color='red'>")
sb.append(zip)
sb.append("</font>")
e.row.cells(2).text = sb.tostring()

and it still displayed as
<font color='red'>300 Any Lane</font>< /br>< /br>Any Town, MI <font color='red'>44444</font>

and not
300 Any Lane

Any Town, MI, 44444
 
</br> should be ignored as it mean 'end tag' (and you don't have a corresponding 'start tag').
The XHtml standard <br/> is valid like the Html standard I posted. (better use XHtml syntax..)
 

Latest posts

Back
Top