我有这样的gridview,我从数据库中获取数据并且它没有标题列
这个gridview没有标题,这些只是行。现在问题是我想格式化该列
在这里你可以看到31 DEC
是星期一,所以我想格式化日期为星期一的每一列。我想改变第一行中星期一的那一列的颜色。所以任何人都可以告诉我在 c# 中这样做的想法。
这应该可以帮助您为匹配的单元格着色
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
}
}
}
我找到了我自己的答案,就像这样
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 ++;
}
}