簡體   English   中英

是否可以設置asp.net gridview單元格的背景?

[英]Is it possible to set the background of a asp.net gridview cell?

可能嗎? 我只能設置單元格的背景顏色。 事情是,如果我設置backgroundcolor,它將不會顯示(默認情況下)打印頁面時。 所以我想通過css將背景設置為網格單元,但是在BoundField.ItemStyle類中找不到這個屬性(只有'backgroundColor')。 那么,這有可能嗎?

提前致謝

你可以試試

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {

      if(condition)//Replace with your condition
      {
        e.Row.Cells[5].Attributes.Add("Style", "background: url(../Images/test.png) no-repeat 5px center
      }
    }
}

試試這個:

在后面的代碼中的RowDataBound事件上,您可以獲取所需單元格的System.Web.UI.WebControls.TableCell對象,並使用CssClass屬性設置其樣式:

e.Row.Cells[0].CssClass = "myStyle"

您可以在GridView上設置RowStyle-CssClass屬性,然后將樣式應用於您擁有CSS樣式的單元格(外部樣式表,頭部等等)。

如果你想在每個單元格中使用它而不是網格視圖上的行,你會添加

ItemStyle-CssClass="class name here"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM