0
A
回答
1
你RowDataBound
事件應該喜歡這個
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[0].Text == "open")
{
e.Row.Cells[0].ForeColor = System.Drawing.Color.Red;
}
else if (e.Row.Cells[0].Text == "close")
{
e.Row.Cells[0].ForeColor = System.Drawing.Color.Black;
}
else
{
e.Row.Cells[0].ForeColor = System.Drawing.Color.Green;
}
}
}
0
首先,您需要定義標記一個GridView
,像這樣:
<asp:GridView id="GridView1" emptydatatext="No data available." runat="server" onrowdatabound="GridView1_RowDataBound" >
<Columns>
<asp:boundfield datafield="CustomerID" headertext="Customer ID"/>
<asp:boundfield datafield="CompanyName" headertext="Company Name"/>
<asp:boundfield datafield="Address" headertext="Address"/>
<asp:boundfield datafield="City" headertext="City"/>
<asp:boundfield datafield="PostalCode" headertext="Postal Code"/>
<asp:boundfield datafield="Country" headertext="Country"/>
</Columns>
</asp:GridView>
注意:您GridView
的DataSource
需要有匹配您GridView
定義的datafield
值公共屬性名稱。
其次,你需要實現你的GridView
定義的onrowdatabound
事件,它指向一個名爲GridView1_RowDataBound
方法,就像這樣:
protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Put logic here to check particular cell value
// Here is an example of changing the second cell (`Cells` collection is zero-based) to italic
e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
}
}
相關問題
- 1. 在angularjs中選擇特定列
- 2. 在陣列中選擇特定線
- 3. 如何在LINQ中選擇特定列?
- 4. 只在mysql中選擇特定的列
- 5. MySQL選擇特定列比選擇*
- 6. 根據特定列中的特定值在SAS中選擇行
- 7. Simple.Data選擇特定列
- 8. doctrine2選擇特定的列
- 9. 選擇從的GroupBy列表中選擇特定的列
- 10. 在LINQ中選擇特定列作爲特定名稱?
- 11. 從列表中選擇特定項目
- 12. 從CSV文件中選擇特定列
- 13. 從兩個表中選擇特定列
- 14. 從表中選擇特定的列名
- 15. 僅選擇Nhibernate中的特定列IQueryable
- 16. Angular ng選項首先在列表中選擇特定選項
- 17. 在jquery中選擇下拉列表中的特定選項
- 18. 選擇特定的行特定的列和特定的輸入
- 19. 在DF和隨機列中選擇一個特定列(python3,pandas)
- 20. 無法在自定義列表中選擇特定對象 - Android
- 21. 如何在android中選擇列表中的特定數據?
- 22. 在Querydsl中只選擇Spring中的特定列?
- 23. 選擇GridView(asp.net)中特定列中的所有複選框
- 24. SQL幫助,選擇特定列
- 25. 從熊貓系列選擇特定值
- 26. 選擇陣列軌特定屬性
- 27. Linq更新,特定選擇列爲空
- 28. 選擇日期列大於特定
- 29. 實體框架 - 選擇特定的列
- 30. 選擇加載的特定列