Editing data before displaying in a GridView

So, basically, my data is extracted from the database, for which I want it to be displayed in gridview. Unfortunately, the days of the week are stored as integers, so Monday is 0, and Tuesday is 1, etc.

Basically, how can I change the data since it is output so that it converts the number to the correct day of the week.

I have a grid view as follows, and at the moment I have it configured using onrowdatabound:

 <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
                        AutoGenerateColumns="False" DataSourceID="SqlDataSource2" Width="721px"  
                        onrowdatabound="GridView_RowDataBound" 
                        >

Then the code for GridView_RowDataBound:

  protected void GridView_RowDataBound(Object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {

        }

    }

, . - . , . , , , !

!

        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";

        }

    }
+3
1

.

if (e.Row.RowType == DataControlRowType.DataRow)
{
     string days = e.Row.Cells[2].Text;
     if (days == "0") e.Row.Cells[2].Text = "Monday";
     if (days == "1") e.Row.Cells[2].Text = "Tuesday";
     if (days == "2") e.Row.Cells[2].Text = "Wednesday";
     if (days == "3") e.Row.Cells[2].Text = "Thursday";
     if (days == "4") e.Row.Cells[2].Text = "Friday";
}
+3

All Articles