gridview第一行单元格文本

时间:2013-01-09 06:15:25

标签: c# gridview

我有这样的gridview,我从数据库中获取数据并且没有标题列

enter image description here

这个gridview没有标题这些只是行。现在问题是我要格式化那个列

这里你可以看到31 DEC是星期一,所以我想格式化日期为星期一的每一列。我想改变第一行星期一那列的颜色。所以任何人都可以告诉我这个想法在c#中执行此操作。

2 个答案:

答案 0 :(得分:2)

这可以帮助您为匹配单元着色

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 
    }
   }
}

答案 1 :(得分:0)

我发现自己的答案就像这样

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 ++;
                    }
                }
相关问题