So basically I have data being pulled from a database for which I want it to display in a gridview. Unfortunately, the days of the week are stored as integers so that monday is equal to 0 and tuesday is 1 etc etc.
Basically, how do I go about changing that data as it is being outputted so that it converts the number to the correct day of the week.
I have got a grid view as follows and at the moment I have it set up with onrowdatabound :
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource2" Width="721px"
onrowdatabound="GridView_RowDataBound"
>
Then the code behind for GridView_RowDataBound is :
protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
}
}
I assume that I just need to put the right code in there. However, for some reason I can't do anything to a single cell only to every single cell in a particular column. So I could change every cell in one column to bold but can't individually change a cell. I'm sure there is a way but can't fathom how to do it!
Any help would be much appreciated!
Thanks
protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int days = (int)GridView1.Rows[e.Row.RowIndex].Cell[2].Text;
if (days == 0) GridView1.Rows[e.Row.RowIndex].Cell[2].Text = "Monday";
if (days == 1) GridView1.Rows[e.Row.RowIndex].Cell[2].Text = "Tuesday";
if (days == 1) GridView1.Rows[e.Row.RowIndex].Cell[2].Text = "Wednesday";
if (days == 1) GridView1.Rows[e.Row.RowIndex].Cell[2].Text = "Thursday";
if (days == 1) GridView1.Rows[e.Row.RowIndex].Cell[2].Text = "Friday";
}
}