如果单元格行值相等,则 asp.net 网格视图

本文关键字:asp net 网格 视图 单元格 如果 | 更新日期: 2023-09-27 18:33:16

我正在填充一个数据表,然后将其绑定到网格视图。现在我正在读取网格中的行并为行着色if value = [x].

当我尝试在页面上显示彩色行时,它会重复。假设我已经为 1 行着色,但response.write的结果将是相同的 100 倍。以下是我的代码,希望有人可以提供帮助:

protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    string alert = Request.QueryString["check"];
    // loop over all the Rows in the Datagridview 
    foreach (GridViewRow row in gv1.Rows)
    {
        // if condition is met color the row text 
        if (gv1.Rows[0].Cells[0].Text.ToString() == alert)
        {
            Session ["fn"] = gv1.Rows[0].Cells[2].Text;
            gv1.Rows[0].ForeColor = Color.Red;
    }
        Response.Write(Session["fn"]);
}

如果单元格行值相等,则 asp.net 网格视图

protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    string alert = Request.QueryString["check"];
        if (e.Row.Cells[0].Text.ToString() == alert)
        {
            Session ["fn"] = e.Rows.Cells[2].Text;
            e.Rows.ForeColor = Color.Red;
        Response.Write(Session["fn"]);
        }
}