在Gridview中选择时突出显示行

时间:2014-01-28 09:53:55

标签: asp.net vb.net gridview

我有一个显示年份和按钮(3列)的子,我设法在RowDataBound上更改按钮,但我也想要突出显示,我有e.Row.BackColor = Color.FromArgb(0, 121, 139, 169)但是太硬编码了。< / p>

我的dataAdapter Select FIN_ID, FIN_Name From FinancialYears Where GetDate() >= FIN_DateStart And GetDate() <= FIN_DateEnd

VB代码:

Protected Sub grdFinYear_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdFinYear.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then

            If grdFinYear.DataKeys(e.Row.RowIndex).Values("FIN_ID") = FIN_ID Then
                If FIN_ID = e.Row.FindControl("hdnRecordID") Then
                    '    grdFinYear.SelectedIndex = e.Row.RowIndex
                    'End If
                    Dim activeButton As Button = e.Row.FindControl("btnSelect")
                    'e.Row.BackColor = Color.FromArgb(0, 121, 139, 169)
                    activeButton.CssClass = "ActionButtonsActiveYear"
                Else
                    Dim makeActiveButton As Button = e.Row.FindControl("btnSelect")
                    'Dim button As Button = grdFinYear.Rows(i).FindControl("btnSelect")
                    'button.Text = "MAKE THIS YEAR ACTIVE"
                    'button.Width = 175
                    makeActiveButton.CssClass = "ActionButtonsMakeThisYearActive"

                End If
            End If
    End Sub
HTML中的

我有

<asp:HiddenField ID="hdnRecordID" runat="server" Value='<%#Bind("FIN_ID") %>' />

2 个答案:

答案 0 :(得分:0)

只需创建arraylist

即可
ArrayList arr = new ArrayList();

继续将selected rows更改颜色的ID添加到arraylist

最后将其保存在Session variable

Session["rows"] = arr;

下次选择另一个row

获取arraylist返回

ArrayList arr = (ArrayList)Session["rows"];

使用新行循环并重新着色旧行,并将新行添加到arraylist并将其保存回session

答案 1 :(得分:0)

试试这个

   if ((e.Row.RowType == DataControlRowType.DataRow & ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit))) 
    {   
       e.Row.BackColor = Drawing.Color.Yellow;   
    }