3

我正在填充数据表,然后将其绑定到网格视图。现在我正在读取网格中的行并为行着色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"]);
}
4

1 回答 1

2
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"]);
        }
}
于 2013-09-29T10:07:22.957 回答