0

I have gridview like this in which i am fetching data from database and it have no header column

enter image description here

this gridview have no header these are rows only.Now Problem is that i want to format that column in which

here u can see 31 DEC is monday so i want to format the each column in which date is monday.I want to change color of that column which monday in first row .So any one can tell me the idea to do this in c#.

leppie
  • 115,091
  • 17
  • 196
  • 297
Adeel Aslam
  • 1,285
  • 10
  • 36
  • 69

2 Answers2

2

This Should Help You To Color You Matching Cell

protected void grid_RowDataBound(Object sender, GridViewRowEventArgs e) 
{
  if (e.Row.RowType = DataControlRowType.DataRow)
  {
    //Check your condition here
    //Get Id from here and based on Id check value in the 
    //underlying dataSource Row Where you have "Done" column Value
    // e.g.
    // (gridview.DataSource as DataTable), now you can find your row and cell 
    // of "Done"
    If(Condition True)
    {
        e.Row.BackColor = Drawing.Color.Red  // your color settings 
    }
   }
}
andy
  • 5,979
  • 2
  • 27
  • 49
Jignesh.Raj
  • 5,776
  • 4
  • 27
  • 56
0

I found my Own Answer as like this

foreach (TableCell cell in e.Row.Cells) {
                    if (cell.Text != "-1" && cell.Text != "Cotton Arrival") {

                        char[] c = new char[7];
                        c = cell.Text.ToCharArray();

                        string datee = c[0].ToString()+c[1].ToString() ;
                        string monthh = c[2].ToString() + c[3].ToString();
                        string yearr = c[4].ToString() + c[5].ToString() + c[6].ToString() + c[7].ToString();

                        DateTime dtime = new DateTime(Convert.ToInt32(yearr),Convert.ToInt32(monthh),Convert.ToInt32(datee));

                        string day = dtime.DayOfWeek.ToString() ;

                        if (day.ToLower() == "monday") 
                        {
                            GridView1.Columns[count].ItemStyle.CssClass = "monday";
                            GridView2.Columns[count].ItemStyle.CssClass = "monday";
                            GridView3.Columns[count].ItemStyle.CssClass = "monday";
                            GridView4.Columns[count].ItemStyle.CssClass = "monday";
                            break;
                        }
                        count ++;
                    }
                }
Adeel Aslam
  • 1,285
  • 10
  • 36
  • 69