GridView formatting rows/columns question

J

J055

Hi

I've been looking into different ways of formatting columns/rows in the
GridView control. I realize now, I think, that once the datasource is bound
to the control the original column type information is lost, i.e. converted
to a string.

So my question is: is it better to format data while it's still in a
DataTable, for example, then bind it to the control, or format the strings
in the BoundField elements, or if more flexibility is needed, in the
RowDataBound event?

If I do the later then I end up doing things like this:

cell = (DataControlFieldCell)(e.Row.Controls[MYDATE_COLUMN])
cell.Text = cell.Text.Substring(0, 16)

Or converting the string to a date and then formatting the date back to a
string.

I'm sure there are better ways so I'm just wondering if anyone has some good
experience with these kinds of issues?

Thanks

Andrew
 
G

Guest

If you want to format the output you could use the DataFormatString property
of the relevent column within the GridViewControl. You could also use the
CAST and CONVERT funtions in your Select Query so that the data is already
formatted the way you require.
 
S

Steven Cheng[MSFT]

Hi Andrew,

As for data formatting, I always think it should be done in databound
control(for asp.net application) since such formatting is the work in
presentation layer, while datatable is the component in data accessing
layer. It's better to separate them so as to make the different layer loose
coupled.


Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may

learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top