2014-01-27 43 views
0

我有一個RowDataBoundgridview,尋找哪一年是活躍的,現在它有一個,它突出顯示。但讓我們說,我想再次活躍一年,但仍然突出顯示,並且您點擊的那個也突出顯示。但我想在RowDataBound gridview所選顏色

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 
      Dim activeButton As Button = e.Row.FindControl("btnSelect") 
      activeButton.CssClass = "ActionButtonsActiveYear" 
      e.Row.BackColor = Color.FromArgb(0, 121, 139, 169) 
     Else 
      Dim makeActiveButton As Button = e.Row.FindControl("btnSelect") 
      makeActiveButton.CssClass = "ActionButtonsMakeThisYearActive" 
     End If 
    End If 
    End Sub 

C#或VB幫助是值得歡迎的,所以我認爲它會不得不用這樣的selectedindexchange。但這SUB是一半沒用,不是嗎?

回答

0

試圖完全理解....但我認爲你需要做什麼來改變年,你將需要重新綁定網格,這將運行你的rowdatabound代碼並改變亮點。

+0

是的,在我的表單的負載中,我將FIN年設置到今年,所以也許在那裏我可以說,如果年份更改爲無論如何改變按鈕和HILIGHT。那是對的嗎? – TheUser

0

沒有看到你所有的代碼,很難說......但是在頁面加載時,你設置了FIN年(只有在不回發的情況下才這樣做)。

修改你的RowDataBound代碼添加一些的CommandName和CommandArgument屬性的btnSelect是這樣的...

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 
     Dim activeButton As Button = e.Row.FindControl("btnSelect") 
     activeButton.CssClass = "ActionButtonsActiveYear" 
     activeButton.CommandName = "ActiveButton" 
     activeButton.CommandArgument = **Bind to Year for this row** 
     e.Row.BackColor = Color.FromArgb(0, 121, 139, 169) 
    Else 
     Dim makeActiveButton As Button = e.Row.FindControl("btnSelect") 
     makeActiveButton.CssClass = "ActionButtonsMakeThisYearActive" 
     makeActiveButton.CommandName = "MakeActiveButton" 
     makeActiveButton.CommandArgument = **Bind to Year for this row** 
    End If 
End If 
End Sub 
在您的btnSelect.click事件代碼

則...

Protected Sub btnSelect_Click(ByVal sender As Object, ByVal e as EventArgs) Handles btnSelect.Click 
    If sender.CommandName = "MakeActiveButton" Then 
     FIN = CInt(sender.CommandArgument) 
     grdFIinYear.DataBind() 
    End If 
End Sub 

希望那幫助