データベースからデータをフェッチしているこのようなグリッドビューがあり、ヘッダー列がありません
このグリッドビューにはヘッダーがありません。これらは行のみです。問題は、その列をフォーマットしたいということです。
ここで見ることができる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 ++;
}
}