我有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 :(得分:0)
试图完全理解....但我认为当年份改变时你需要做什么,你需要重新绑定网格,这将运行你的rowdatabound代码并改变亮点。
答案 1 :(得分: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
希望能帮助