gpt4 book ai didi

c# - 如何根据 gridview 中的列值制作组(部分)?

转载 作者:行者123 更新时间:2023-11-30 13:05:44 24 4
gpt4 key购买 nike

在我的网格中,我在两列中有几行相同的数据。然后其他几行将与不同的数据相同。我想将它们变成带有颜色的替代部分

在下面的例子中(图片)。

Rows no 1 to 4 has 'High', 'High'. I want make them gray bgcolor  for those rows.
Rows no 5 to 8 has 'High','Low'. I want make them white bgcolor for those rows
Rows no 9 to 12 has 'High','Medium'. I want make them again gray bg color for
those rows.

alt text

我们怎样才能做到这一点?

最佳答案

好的——只需修改 Leniel Macaferi 的回答:(我混合了一点 w/vb,因为我不是 c# 的人——抱歉——尽管我希望这一点仍然很清楚)

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Display the company name in italics.
Session("New_Pair_1") = e.Row.Cells[1].Text
Session("New_Pair_2") = e.Row.Cells[2].Text

If Session("New_Pair_1") <> Session("OLD_Pair_1") OR _
Session("New_Pair_2") <> Session("OLD_Pair_2") Then
//no pair match with last record's pair
//step 1, change the backcolor
If e.Row.BackColor = Color.FromName("Gray") Then
e.Row.BackColor = Color.FromName("White")
Else
e.RowlBackColor = Color.FromName("Gray")
End If
//Step 2, reset the "OLD" session vars
Session("OLD_Pair_1") = Session("New_Pair_1")
Session("OLD_Pair_2") = Session("New_Pair_2")
End If
}
}

关于c# - 如何根据 gridview 中的列值制作组(部分)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3338699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com