in my web application I have a gridview where I have data from a database. It looks like this:
number | place |
---|---|
1234579 | home2 |
1787543 | home1 |
And i want edit fist column (number
) to format – fifth character from right side bold and three characters from right side also bold.
number | place |
---|---|
1234579 | home2 |
1787543 | home1 |
How can I achieve this? I work in a visual studio, it can be set in design mode or in the source, or how. Thanks
2
Answers
You can use the
TemplateField
to move the data to code behind and format there as you wish – because here you have to split your number and then reformat it.So inside the GridView add a
<asp:TemplateField>
and on code behind do your format..
Well it is assumed the source is some kind of database, so bottom line is you have to pull that data and format it with code.
I mean, trivial to make the WHOLE column bold. But this is a bit of whack job of a request here.
Ok, so we have say this data in a table:
And our markup would be this:
Ok, our code to load the grid is this:
and we now have this:
Now, as a "general" rule, formatting grids/listview etc, we can try and inject message server expressions into the markup, but for setting color, highlights, and formatting it better to use the databound event of that control.
So, we could have this code:
And now our output is this:
So, for changing status and formatting the grid (say a color for status etc.), then the above is the general appoarch.
Of course we need some function called MyBold.
Say like this: