gridview的突出当前行 [英] gridview highlighting current row

查看:135
本文介绍了gridview的突出当前行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有突出在一个gridview当前所选行的一个内置的方法?

Is there a built-in method of highlighting the currently selected row in a gridview?

在我的GridView的每一行都有一个按钮(通过ButtonField字段)。当用户presses此按钮,背景颜色的变化......我这样做是这样的:

Each row in my gridview has a button (via a buttonField). When the user presses this button, the background color changes...I do it like this:

Protected Sub gvTransferOwner_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvTransferOwner.RowCommand
    If e.CommandName = "Select" Then
        Dim index As Integer = Convert.ToInt32(e.CommandArgument)
        Dim selectedRow As GridViewRow = gvTransferOwner.Rows(index)
        selectedRow.Style.Add("background-color", "#ffcccc")
    End If
End Sub

这凸显了该行,但是一旦用户presses另一行的按钮,它仍然保留了所有的previously- pressed行的颜色。

This highlights the row, but once the user presses the button in another row, it still retains that color in all previously-pressed rows.

有没有一种方法,以便只有一次行(当前所选行)突出显示?

Is there a way so that only one row at a time(the currently selected row) is highlighted?

感谢

推荐答案

如果您使用全局变量来存储被选定行的索引,您可以更改该行回原来的颜色每当一个新行选中。

If you use a global variable to store the index of the row that is being selected, you can change that row back to the original color whenever a new row is selected.

Dim previousSelected As Integer 'global variable to store the last selected index
Protected Sub gvTransferOwner_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvTransferOwner.RowCommand
    If e.CommandName = "Select" Then
        Dim index As Integer = Convert.ToInt32(e.CommandArgument)
        Dim selectedRow As GridViewRow = gvTransferOwner.Rows(previousSelected)
        selectedRow.Style.Add("background-color", "#ffffff") 'change it back to original color
        selectedRow = gvTransferOwner.Rows(index)
        selectedRow.Style.Add("background-color", "#ffcccc") 'change the color of the new row
        previousSelected = index
    End If
End Sub

这篇关于gridview的突出当前行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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