Hi i want to find the column name of the cell in the below event of a datagridview.
protected void grvDetailedStatus_ItemDataBound(object sender, DataGridItemEventArgs e)
{
for (int i = 0; i <= e.Item.Cells.Count - 1; i++)
{
System.DateTime cellDate = default(System.DateTime);
if (System.DateTime.TryParse(e.Item.Cells[i].Text, out cellDate))
{
e.Item.Cells[i].Text = string.Format("{0:d}", cellDate);
}
}
}
Is there any way to find the column name of the cell i am manupulating.
Please help .
Hi, Sorry for not giving a clear explanation.Let me explain it more clearly.
I want to do the below formating only for particular column values
protected void grvDetailedStatus_ItemDataBound(object sender, DataGridItemEventArgs e)
{
for (int i = 0; i <= e.Item.Cells.Count - 1; i++)
{
System.DateTime cellDate = default(System.DateTime);
if (System.DateTime.TryParse(e.Item.Cells[i].Text, out cellDate))
{
e.Item.Cells[i].Text = string.Format("{0:d}", cellDate);
}
}
}
Say for example i have to change the format of the date only for the "column1" and "column5" .So now i want to know the column name and with that i want to format that column alsone and leave the rest.
protected void grvDetailedStatus_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if ( columnName == "Column1")
{
for (int i = 0; i <= e.Item.Cells.Count - 1; i++)
{
System.DateTime cellDate = default(System.DateTime);
if (System.DateTime.TryParse(e.Item.Cells[i].Text, out cellDate))
{
e.Item.Cells[i].Text = string.Format("{0:d}", cellDate);
}
}
}
}
.