Change Rows Background color in GridView with selected Criteria
来源:互联网 发布:js中的事件委托 编辑:程序博客网 时间:2024/06/04 08:46
In this article we change background color of the rows in a GridView with selected criteria on GridView1_RowDataBound event.
In aspx.cs page
In aspx.cs page write the code for the Gridview1_RowDataBound Event. Set the criteria you want for the Gridview Row Backcolor Change. The GridView offers a RowDataBound event that fires once for each row after the row has been created and bound to the corresponding record of data from the data source control. In this article I am changing the row background color when CategoryID == 2; you can use whatever criteria you need to.
protectedvoid Gridview1_RowDataBound(object sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// determine the value of the UnitsInStock field
int CategoryID = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem,"CategoryID"));
if (CategoryID == 2)
// color the background of the row yellow
e.Row.BackColor = System.Drawing.Color.Brown;
}
}
In aspx page
In the aspx page on the GridView set the RowDataBound event in the GridView property. Then, in the RowDataBound line, type in the name of the event handler you want to create (I named my event handler productsGridView_RowDataBound). Finally, enter in the following code into the event handler on OnRowDataBound="Gridview1_RowDataBound" .
Conclusion
In this article we try to improve GridView design based on certain criteria. Hopefully it's useful for you.
- Change Rows Background color in GridView with selected Criteria
- How to: Change color of rows in GridView on mouseover
- change background color in chrome
- Getting all selected rows in ADF Table with multiple rows selection enabled
- How to change tooltip background color in Unity?
- Android change background color smoothly
- How to change the text color of the selected property sheet tab in Visual C++
- how can i change the back color on mouse out to the color specified in gridview
- Change the xterm background color for ICEWM
- change dir color in terminal
- How to access selected rows in an af:selectManyChoice component
- How To Change the Background Color of a Tab Control
- how to change the background color of actionbar
- qt 之 How to Change the Background Color of QWidget
- Change text color on listView with buttons
- Get GridView selected row DataKey in Javascript
- change the color scheme in vim
- change background
- ASP.NET中设置CheckBox和RadioButton的默认值不可改变
- Java读写网络图片,相当于图片下载或图片另存为
- c++阿拉伯数字转中文字符
- 利用bind9架设智能DNS——postgreSQL数据库篇
- 我勒个去,苹果你故意的吧?又丢手机了?
- Change Rows Background color in GridView with selected Criteria
- Nginx反向代理到apache
- 项目经理的职责和权利
- ubuntu下mysql安装(server、client、dev),开启、停止和重启,及常见错误
- 用grouping求小计和合计
- linux 备份系统方法
- Java拼接多张图片,可以连接在一起
- paradox数据库的创建与数据操作
- java 内部类