在GridView中更改特定记录的样式

时间:2013-07-25 05:27:37

标签: asp.net gridview format aspxgridview

我正在ASP.Net中设计一个物流系统。在订单处理页面中,订单由网格视图显示,我想将行的字体样式更改为BOLD,标记为“ordedr not processed”。谢谢。

order processing page

2 个答案:

答案 0 :(得分:3)

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        string OrStatus = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Orderstatus"));
        if (OrStatus == "Order not processed")
        {
            //You can use whatever you want to play with rows
            e.Row.Cells[0].Font.Bold = true;
            e.Row.Cells[2].CssClass = "gridcss";
        }
    }
}

遵循该代码。这将有所帮助

答案 1 :(得分:2)

您可以在网格的“rowdatabound”事件中执行此操作。

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridView grid = GridView1;
            GridViewRow row = e.Row;
            if (row.RowType == DataControlRowType.DataRow)
            {

               string orderstatus= Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Orderstatus"));
              if(orderstatus=="Order not processed)
              {
                   //write your code to change css
              }
            }
        }