如何突出显示DetailsView中的特定行? [英] How to highlight specific row in a DetailsView?

查看:108
本文介绍了如何突出显示DetailsView中的特定行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是新的ASP.NET开发人员.我现在正在使用DetailsView从数据库中分发一些数据.我需要突出显示DetailsView中的某些两行.两行都是VARCHAR数据类型.

Hello everybody,

I am a new ASP.NET developer. I am using a DetailsView now to dispaly some data from the database. I have the need to highlight certain two rows from the DetailsView. Both rows are VARCHAR data type.
SO HOW TO DO THAT?

推荐答案

重写数据绑定事件并设置e.Row.BackColor = System.Drawing.Color.Red;.或任何一种颜色,如果您需要执行一些逻辑来查找需要突出显示的行.

Override the databound event and set the e.Row.BackColor = System.Drawing.Color.Red; or what ever color, if you have some logic to execute for finding the row that needs to be highlighted.

protected void detailsView_RowDataBound(object sender, 
GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if(...)//some condition for selection of row to be higlighted
        {
           e.Row.BackColor = System.Drawing.Color.Red;
        }
}
}



如果您需要一个垂直的行,比如说要突出显示第4行,然后将其固定,那么您可以直接这样



If you need a perticular row, say 4th row to be highlighted and that''s fixed then you could directly like this

detailsViewGrid.Rows[2].Row.BackColor = System.Drawing.Color.Red;



您唯一需要记住的是,此代码仅在 DetailsView_rowdatabound事件(如预渲染)之后发生的那些事件中编写.



The only thing you need to keep in mind that this code would be written in only those events which would come after detailsView_rowdatabound event(Like pre-render)


这篇关于如何突出显示DetailsView中的特定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆