By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,230 Members | 1,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,230 IT Pros & Developers. It's quick & easy.

Format Data in BoundColumns of DataGrid

P: n/a
Hi

I want to format some columns of my DataGrid control.
Example, one of my fields of DataSet is a DATE field and in BD he is Ok, but
when I show him in datagrid he comes with hours too. I don´t want that.

2nd Example:
Field in BD:
DtSegm
17-02-2004
Note: When I save to DB I format Date to put like above

In DataGrid shows like this:
DtSegm
17-02-2004 10:30:45

How can I change that.
--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca
Nov 18 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
If you are using simple bound columns (using the Property builder) you may
asign the Data Format box in the property builder, or manually assign a
DataFormatString attribute in HTML view

If its a templated column, you may add the format as the third argument to
the Eval function, as in:

DataBinder.Eval(Container, "DataItem.DueDate", "d")

Regards
Jose.

"ruca" <ru***@iol.pt> escribió en el mensaje
news:eo**************@TK2MSFTNGP09.phx.gbl...
Hi

I want to format some columns of my DataGrid control.
Example, one of my fields of DataSet is a DATE field and in BD he is Ok, but when I show him in datagrid he comes with hours too. I don´t want that.

2nd Example:
Field in BD:
DtSegm
17-02-2004
Note: When I save to DB I format Date to put like above

In DataGrid shows like this:
DtSegm
17-02-2004 10:30:45

How can I change that.
--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

Nov 18 '05 #2

P: n/a
Hi, ruca,

You can achive this by setting the DataFormatString property of the
BoundColumn approprietly:

http://msdn.microsoft.com/library/en...tringtopic.asp

Set it to "dd-MM-yyyy". See the following link for more valid custom
DateTime format strings:

http://msdn.microsoft.com/library/en...matstrings.asp

Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
Hi

I want to format some columns of my DataGrid control.
Example, one of my fields of DataSet is a DATE field and in BD he is Ok, but when I show him in datagrid he comes with hours too. I don´t want that.

2nd Example:
Field in BD:
DtSegm
17-02-2004
Note: When I save to DB I format Date to put like above

In DataGrid shows like this:
DtSegm
17-02-2004 10:30:45

How can I change that.
--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

Nov 18 '05 #3

P: n/a
What's wrong with this:

<asp:BoundColumn DataField="DtSgm" ReadOnly="True" HeaderText="DtSegmento"
DataFormatString="DtSgm.ToString('dd-MM-YYYY')"></asp:BoundColumn>

"Martin Dechev" <de*******@hotmail.com> escreveu na mensagem
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hi, ruca,

You can achive this by setting the DataFormatString property of the
BoundColumn approprietly:

http://msdn.microsoft.com/library/en...webuiwebcontro
lsboundcolumnclassdataformatstringtopic.asp
Set it to "dd-MM-yyyy". See the following link for more valid custom
DateTime format strings:

http://msdn.microsoft.com/library/en...omdatetimeform
atstrings.asp
Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
Hi

I want to format some columns of my DataGrid control.
Example, one of my fields of DataSet is a DATE field and in BD he is Ok,

but
when I show him in datagrid he comes with hours too. I don´t want that.

2nd Example:
Field in BD:
DtSegm
17-02-2004
Note: When I save to DB I format Date to put like above

In DataGrid shows like this:
DtSegm
17-02-2004 10:30:45

How can I change that.
--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca


Nov 18 '05 #4

P: n/a
Hi, ruca,

You haven't read the article for the DataFormatString property, have you?

<asp:BoundColumn DataField="DtSgm" ReadOnly="True" HeaderText="DtSegmento"
DataFormatString="dd-MM-yyyy"/>

Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eP**************@TK2MSFTNGP09.phx.gbl...
What's wrong with this:

<asp:BoundColumn DataField="DtSgm" ReadOnly="True" HeaderText="DtSegmento"
DataFormatString="DtSgm.ToString('dd-MM-YYYY')"></asp:BoundColumn>

"Martin Dechev" <de*******@hotmail.com> escreveu na mensagem
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hi, ruca,

You can achive this by setting the DataFormatString property of the
BoundColumn approprietly:

http://msdn.microsoft.com/library/en...webuiwebcontro lsboundcolumnclassdataformatstringtopic.asp

Set it to "dd-MM-yyyy". See the following link for more valid custom
DateTime format strings:

http://msdn.microsoft.com/library/en...omdatetimeform atstrings.asp

Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
Hi

I want to format some columns of my DataGrid control.
Example, one of my fields of DataSet is a DATE field and in BD he is Ok,
but
when I show him in datagrid he comes with hours too. I don´t want

that.
2nd Example:
Field in BD:
DtSegm
17-02-2004
Note: When I save to DB I format Date to put like above

In DataGrid shows like this:
DtSegm
17-02-2004 10:30:45

How can I change that.
--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca



Nov 18 '05 #5

P: n/a
How can I format a Field that I have to calculate something.
Like this:
Field1 in DB is a Double
Field1 = 0.11

And I want to appear: 0.11 * 100 = 11
Thanks

"Martin Dechev" <de*******@hotmail.com> escreveu na mensagem
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hi, ruca,

You can achive this by setting the DataFormatString property of the
BoundColumn approprietly:

http://msdn.microsoft.com/library/en...webuiwebcontro
lsboundcolumnclassdataformatstringtopic.asp
Set it to "dd-MM-yyyy". See the following link for more valid custom
DateTime format strings:

http://msdn.microsoft.com/library/en...omdatetimeform
atstrings.asp
Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
Hi

I want to format some columns of my DataGrid control.
Example, one of my fields of DataSet is a DATE field and in BD he is Ok,

but
when I show him in datagrid he comes with hours too. I don´t want that.

2nd Example:
Field in BD:
DtSegm
17-02-2004
Note: When I save to DB I format Date to put like above

In DataGrid shows like this:
DtSegm
17-02-2004 10:30:45

How can I change that.
--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca


Nov 18 '05 #6

P: n/a
I've got working now. I already understand how can I format string's in the
way that I want. Thank's Martin.

But now I have another question:

How can I format a Field that I have to calculate something.
Like this:
Field1 in DB is a Double
Field1 = 0.11

And I want to appear: 0.11 * 100 = 11
Thanks

"Martin Dechev" <de*******@hotmail.com> escreveu na mensagem
news:#y**************@TK2MSFTNGP09.phx.gbl...
Hi, ruca,

You haven't read the article for the DataFormatString property, have you?

<asp:BoundColumn DataField="DtSgm" ReadOnly="True" HeaderText="DtSegmento"
DataFormatString="dd-MM-yyyy"/>

Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eP**************@TK2MSFTNGP09.phx.gbl...
What's wrong with this:

<asp:BoundColumn DataField="DtSgm" ReadOnly="True" HeaderText="DtSegmento"
DataFormatString="DtSgm.ToString('dd-MM-YYYY')"></asp:BoundColumn>

"Martin Dechev" <de*******@hotmail.com> escreveu na mensagem
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hi, ruca,

You can achive this by setting the DataFormatString property of the
BoundColumn approprietly:

http://msdn.microsoft.com/library/en...webuiwebcontro
lsboundcolumnclassdataformatstringtopic.asp

Set it to "dd-MM-yyyy". See the following link for more valid custom
DateTime format strings:

http://msdn.microsoft.com/library/en...omdatetimeform
atstrings.asp

Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
> Hi
>
> I want to format some columns of my DataGrid control.
> Example, one of my fields of DataSet is a DATE field and in BD he is

Ok, but
> when I show him in datagrid he comes with hours too. I don´t want that. >
> 2nd Example:
> Field in BD:
> DtSegm
> 17-02-2004
> Note: When I save to DB I format Date to put like above
>
> In DataGrid shows like this:
> DtSegm
> 17-02-2004 10:30:45
>
> How can I change that.
>
>
> --
>
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>
>



Nov 18 '05 #7

P: n/a

It should be "{0:dd-MM-yyyy}" in this case, sorry for the mistake.

Hope this helps
Martin

"Martin Dechev" <de*******@hotmail.com> wrote in message
news:#y**************@TK2MSFTNGP09.phx.gbl...
Hi, ruca,

You haven't read the article for the DataFormatString property, have you?

<asp:BoundColumn DataField="DtSgm" ReadOnly="True" HeaderText="DtSegmento"
DataFormatString="dd-MM-yyyy"/>

Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eP**************@TK2MSFTNGP09.phx.gbl...
What's wrong with this:

<asp:BoundColumn DataField="DtSgm" ReadOnly="True" HeaderText="DtSegmento"
DataFormatString="DtSgm.ToString('dd-MM-YYYY')"></asp:BoundColumn>

"Martin Dechev" <de*******@hotmail.com> escreveu na mensagem
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hi, ruca,

You can achive this by setting the DataFormatString property of the
BoundColumn approprietly:

http://msdn.microsoft.com/library/en...webuiwebcontro
lsboundcolumnclassdataformatstringtopic.asp

Set it to "dd-MM-yyyy". See the following link for more valid custom
DateTime format strings:

http://msdn.microsoft.com/library/en...omdatetimeform
atstrings.asp

Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
> Hi
>
> I want to format some columns of my DataGrid control.
> Example, one of my fields of DataSet is a DATE field and in BD he is

Ok, but
> when I show him in datagrid he comes with hours too. I don´t want that. >
> 2nd Example:
> Field in BD:
> DtSegm
> 17-02-2004
> Note: When I save to DB I format Date to put like above
>
> In DataGrid shows like this:
> DtSegm
> 17-02-2004 10:30:45
>
> How can I change that.
>
>
> --
>
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>
>



Nov 18 '05 #8

P: n/a
1. In the grid's Property Builder page, clear the "Data Format" field and
then convert your "bound column" into a "templated column" using the
provided link

2. Edit the HTML and replace the binding expression as follows (assuming
DataItem.Qty is an integer)

Instead of
<%# DataBinder.Eval(Container, "DataItem.Qty") %>
use
<%# (((int)DataBinder.Eval(Container,
"DataItem.Qty"))*100).ToString("d9") %>

Regards
Jose.

"ruca" <ru***@iol.pt> escribió en el mensaje
news:O8**************@TK2MSFTNGP09.phx.gbl...
How can I format a Field that I have to calculate something.
Like this:
Field1 in DB is a Double
Field1 = 0.11

And I want to appear: 0.11 * 100 = 11
Thanks

"Martin Dechev" <de*******@hotmail.com> escreveu na mensagem
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hi, ruca,

You can achive this by setting the DataFormatString property of the
BoundColumn approprietly:

http://msdn.microsoft.com/library/en...webuiwebcontro lsboundcolumnclassdataformatstringtopic.asp

Set it to "dd-MM-yyyy". See the following link for more valid custom
DateTime format strings:

http://msdn.microsoft.com/library/en...omdatetimeform atstrings.asp

Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
Hi

I want to format some columns of my DataGrid control.
Example, one of my fields of DataSet is a DATE field and in BD he is Ok,
but
when I show him in datagrid he comes with hours too. I don´t want

that.
2nd Example:
Field in BD:
DtSegm
17-02-2004
Note: When I save to DB I format Date to put like above

In DataGrid shows like this:
DtSegm
17-02-2004 10:30:45

How can I change that.
--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca



Nov 18 '05 #9

P: n/a
<%# (((int)DataBinder.Eval(Container,"DataItem.Qty"))* 100).ToString("d9") %>

The part of ToString("d9") doesn't work.
I have to set this value: DataBinder.Eval(Container,"DataItem.Qty"))*100)
into a double of 2 decimal places

How?

"Jose Marcenaro" <jo***@nospam.da-vinci.com.ar> escreveu na mensagem
news:OP**************@TK2MSFTNGP09.phx.gbl...
1. In the grid's Property Builder page, clear the "Data Format" field and
then convert your "bound column" into a "templated column" using the
provided link

2. Edit the HTML and replace the binding expression as follows (assuming
DataItem.Qty is an integer)

Instead of
<%# DataBinder.Eval(Container, "DataItem.Qty") %>
use
<%# (((int)DataBinder.Eval(Container,
"DataItem.Qty"))*100).ToString("d9") %>

Regards
Jose.

"ruca" <ru***@iol.pt> escribió en el mensaje
news:O8**************@TK2MSFTNGP09.phx.gbl...
How can I format a Field that I have to calculate something.
Like this:
Field1 in DB is a Double
Field1 = 0.11

And I want to appear: 0.11 * 100 = 11
Thanks

"Martin Dechev" <de*******@hotmail.com> escreveu na mensagem
news:Op**************@TK2MSFTNGP11.phx.gbl...
Hi, ruca,

You can achive this by setting the DataFormatString property of the
BoundColumn approprietly:

http://msdn.microsoft.com/library/en...webuiwebcontro
lsboundcolumnclassdataformatstringtopic.asp

Set it to "dd-MM-yyyy". See the following link for more valid custom
DateTime format strings:

http://msdn.microsoft.com/library/en...omdatetimeform
atstrings.asp

Greetings
Martin
"ruca" <ru***@iol.pt> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
> Hi
>
> I want to format some columns of my DataGrid control.
> Example, one of my fields of DataSet is a DATE field and in BD he is Ok, but
> when I show him in datagrid he comes with hours too. I don´t want that. >
> 2nd Example:
> Field in BD:
> DtSegm
> 17-02-2004
> Note: When I save to DB I format Date to put like above
>
> In DataGrid shows like this:
> DtSegm
> 17-02-2004 10:30:45
>
> How can I change that.
>
>
> --
>
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>
>



Nov 18 '05 #10

P: n/a
Use either .ToString("#.00")
or .ToString("#,###.00") if you want thousands separators

"ruca" <ru***@iol.pt> escribió en el mensaje
news:eJ****************@TK2MSFTNGP12.phx.gbl...
<%# (((int)DataBinder.Eval(Container,"DataItem.Qty"))* 100).ToString("d9") %>
The part of ToString("d9") doesn't work.
I have to set this value: DataBinder.Eval(Container,"DataItem.Qty"))*100)
into a double of 2 decimal places

How?

"Jose Marcenaro" <jo***@nospam.da-vinci.com.ar> escreveu na mensagem
news:OP**************@TK2MSFTNGP09.phx.gbl...
1. In the grid's Property Builder page, clear the "Data Format" field and
then convert your "bound column" into a "templated column" using the
provided link

2. Edit the HTML and replace the binding expression as follows (assuming
DataItem.Qty is an integer)

Instead of
<%# DataBinder.Eval(Container, "DataItem.Qty") %>
use
<%# (((int)DataBinder.Eval(Container,
"DataItem.Qty"))*100).ToString("d9") %>

Regards
Jose.

"ruca" <ru***@iol.pt> escribió en el mensaje
news:O8**************@TK2MSFTNGP09.phx.gbl...
How can I format a Field that I have to calculate something.
Like this:
Field1 in DB is a Double
Field1 = 0.11

And I want to appear: 0.11 * 100 = 11
Thanks

"Martin Dechev" <de*******@hotmail.com> escreveu na mensagem
news:Op**************@TK2MSFTNGP11.phx.gbl...
> Hi, ruca,
>
> You can achive this by setting the DataFormatString property of the
> BoundColumn approprietly:
>
>

http://msdn.microsoft.com/library/en...webuiwebcontro
lsboundcolumnclassdataformatstringtopic.asp
>
> Set it to "dd-MM-yyyy". See the following link for more valid custom
> DateTime format strings:
>
>

http://msdn.microsoft.com/library/en...omdatetimeform
atstrings.asp
>
> Greetings
> Martin
> "ruca" <ru***@iol.pt> wrote in message
> news:eo**************@TK2MSFTNGP09.phx.gbl...
> > Hi
> >
> > I want to format some columns of my DataGrid control.
> > Example, one of my fields of DataSet is a DATE field and in BD he
is Ok,
> but
> > when I show him in datagrid he comes with hours too. I don´t want

that.
> >
> > 2nd Example:
> > Field in BD:
> > DtSegm
> > 17-02-2004
> > Note: When I save to DB I format Date to put like above
> >
> > In DataGrid shows like this:
> > DtSegm
> > 17-02-2004 10:30:45
> >
> > How can I change that.
> >
> >
> > --
> >
> > Thank's (if you try to help me)
> > Hope this help you (if I try to help you)
> > ruca
> >
> >
>
>



Nov 18 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.