我有一个带有一个按钮的Gridview,如果所有行都为true或选中,则按钮状态设置为启用,否则将被禁用。 这是我的代码,但对我不起作用。
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ckbox As CheckBox = CType(e.Row.FindControl("workfinished"), CheckBox)
If ckbox.Checked = True Then
btnFinishedAllWork.Enabled = True
End If
End If
答案 0 :(得分:0)
您应该使用下面提到的示例代码来实现您的要求。
要点如下。
下面的VB.NET代码可更改按钮状态
''In Page_Load event set the button to enabled state and then change its state later
''in page life cycle depending on if a check box is unchecked.
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
btnFinishedAllWork.Enabled = True
End Sub
Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ckbox As CheckBox = CType(e.Row.FindControl("workfinished"), CheckBox)
''only change the state of button any one of the check boxes is unchecked
If ckbox.Checked = False Then
btnFinishedAllWork.Enabled = False
End If
End If
End Sub