DataGrid binding

F

Franck Diastein

Hi,

I'm binding a DataRead (obtained from a mssql SP)to a DataGrid, and one
of the values is a date...

The problem is that date is shown as dd/mm/yyyy hh:mm:ss and I would
like to format it as dd/mm/yyyy...

How can I do it ?

I have seen some code using ItemDataBound event, but I can't manage to
apply them...

TIA
 
E

Eliyahu Goldin

OK, keep trying to apply ItemDataBound event. What is the problem? To format
date use DateTime.ToString (formatString) method with format string
"dd/mm/yyy".

Eliyahu
 
F

Franck Diastein

My problem is that I can't find a sample for to retreive cell value and
reasign to it a new value...
 
E

Eliyahu Goldin

OK, suppose your column 0 contains the date you want to convert.

private void dgSelection_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}
e.Item.Cells[0].Text =
System.Convert.ToDateTime(e.Item.Cells[0].Text ).ToString("dd/mm/yyyy");
}


Eliyahu
 
F

Franck Diastein

OK, that's the code I need... This code give me error with datetime
converstion, but that's another story...

Thanx

Eliyahu said:
OK, suppose your column 0 contains the date you want to convert.

private void dgSelection_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}
e.Item.Cells[0].Text =
System.Convert.ToDateTime(e.Item.Cells[0].Text ).ToString("dd/mm/yyyy");
}


Eliyahu

My problem is that I can't find a sample for to retreive cell value and
reasign to it a new value...

Eliyahu Goldin wrote:


format
 
S

Saravana

Check out "Formatting Dates, Currency, and Other Data" section in this
article,
http://msdn.microsoft.com/library/d...QuestionsAboutASPNETDataGridServerControl.asp

--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com


Franck Diastein said:
OK, that's the code I need... This code give me error with datetime
converstion, but that's another story...

Thanx

Eliyahu said:
OK, suppose your column 0 contains the date you want to convert.

private void dgSelection_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
if ((itemType == ListItemType.Pager) ||
(itemType == ListItemType.Header) ||
(itemType == ListItemType.Footer))
{
return;
}
e.Item.Cells[0].Text =
System.Convert.ToDateTime(e.Item.Cells[0].Text ).ToString("dd/mm/yyyy");
}


Eliyahu

My problem is that I can't find a sample for to retreive cell value and
reasign to it a new value...

Eliyahu Goldin wrote:


OK, keep trying to apply ItemDataBound event. What is the problem? To
format

date use DateTime.ToString (formatString) method with format string
"dd/mm/yyy".

Eliyahu



Hi,

I'm binding a DataRead (obtained from a mssql SP)to a DataGrid, and one
of the values is a date...

The problem is that date is shown as dd/mm/yyyy hh:mm:ss and I would
like to format it as dd/mm/yyyy...

How can I do it ?

I have seen some code using ItemDataBound event, but I can't manage to
apply them...

TIA
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top