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. 如何在LINQ中选择特定列?
- 2. 在阵列中选择特定线
- 3. 只在mysql中选择特定的列
- 4. MySQL选择特定列比选择*
- 5. 根据特定列中的特定值在SAS中选择行
- 6. Simple.Data选择特定列
- 7. 选择从的GroupBy列表中选择特定的列
- 8. 在LINQ中选择特定列作为特定名称?
- 9. 从CSV文件中选择特定列
- 10. 从列表中选择特定项目
- 11. 从两个表中选择特定列
- 12. 仅选择Nhibernate中的特定列IQueryable
- 13. 从表中选择特定的列名
- 14. Angular ng选项首先在列表中选择特定选项
- 15. 在jquery中选择下拉列表中的特定选项
- 16. 选择特定的行特定的列和特定的输入
- 17. 在DF和随机列中选择一个特定列(python3,pandas)
- 18. 无法在自定义列表中选择特定对象 - Android
- 19. 如何在android中选择列表中的特定数据?
- 20. 在Querydsl中只选择Spring中的特定列?
- 21. SQL帮助,选择特定列
- 22. OpenXML选择一个特定的列
- 23. 选择阵列轨特定属性
- 24. 只选择特定的列和ASP.NET
- 25. 选择由联接基于特定列
- 26. 特定的条件下选择列
- 27. 用jquery选择特定范围的列
- 28. SELECT *或选择特定的列
- 29. JPA&Criteria API - 仅选择特定列
- 30. 实体框架 - 选择特定的列