C
ckerns
I want to use this to format the date field in a GridView control.
How would I do this in vb?
-- aspx page --
<asp:GridView runat="server" ID="gridView"
AutoGenerateColumns="true"
OnRowDataBound="gridView_RowDataBound">
-- end aspx page --
-- code beside --
protected void gridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow row = ((DataRowView)e.Row.DataItem).Row;
int index = GetDateColumnIndex(row);
e.Row.Cells[index].Text = ((DateTime)
row[index]).ToString("dd/MM/yyyyyyyy-MM-dd");
}
}
private int dateColumnIndex = -1;
private int GetDateColumnIndex(DataRow row)
{
if (this.dateColumnIndex == -1)
{
this.dateColumnIndex =
row.Table.Columns.IndexOf("ItemRecieved");
if (dateColumnIndex < 0)
{
throw new Exception(
"datasource does not contain the
MyDateColumn column");
}
}
return this.dateColumnIndex;
}
-- end code beside --
How would I do this in vb?
-- aspx page --
<asp:GridView runat="server" ID="gridView"
AutoGenerateColumns="true"
OnRowDataBound="gridView_RowDataBound">
-- end aspx page --
-- code beside --
protected void gridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow row = ((DataRowView)e.Row.DataItem).Row;
int index = GetDateColumnIndex(row);
e.Row.Cells[index].Text = ((DateTime)
row[index]).ToString("dd/MM/yyyyyyyy-MM-dd");
}
}
private int dateColumnIndex = -1;
private int GetDateColumnIndex(DataRow row)
{
if (this.dateColumnIndex == -1)
{
this.dateColumnIndex =
row.Table.Columns.IndexOf("ItemRecieved");
if (dateColumnIndex < 0)
{
throw new Exception(
"datasource does not contain the
MyDateColumn column");
}
}
return this.dateColumnIndex;
}
-- end code beside --