C# gridview第一行cel文本
我有这样的gridview,其中我从数据库中获取数据,它没有标题列 这个gridview没有标题,这些只是行。现在的问题是,我想格式化其中的列C# gridview第一行cel文本,c#,gridview,C#,Gridview,我有这样的gridview,其中我从数据库中获取数据,它没有标题列 这个gridview没有标题,这些只是行。现在的问题是,我想格式化其中的列 在这里你可以看到12月31日是星期一,所以我想格式化每一列的格式,其中日期是星期一。我想更改第一行中星期一列的颜色。所以任何人都可以告诉我在c#中这样做的想法。这应该可以帮助你给匹配的单元格上色 protected void grid_RowDataBound(Object sender, GridViewRowEventArgs e) { if
在这里你可以看到12月31日是星期一,所以我想格式化每一列的格式,其中日期是星期一。我想更改第一行中星期一列的颜色。所以任何人都可以告诉我在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 ++;
}
}
先生,我不想修改列,而我想修改第一个单元格中的星期一。您想按单元格中给定的日期获取日期吗?实际上,第一行r中的日期是动态更改的,而不是固定的,因此我想动态格式化所有列,其中列值为星期一