gpt4 book ai didi

javascript - 取消选中后面代码中 CheckedChanged 上的最后一个复选框

转载 作者:行者123 更新时间:2023-11-27 23:38:52 25 4
gpt4 key购买 nike

我有一个 gridview,其中有一个 itemtemplate 列,其中有一个复选框。我只希望用户选择其中 3 个复选框。在第四次选择时,我想弹出一条消息,告诉他们只允许 3 个,然后取消选中他们刚刚选中的复选框。我尝试了不同的 JavaScript,但无法让它工作。

现在我非常接近在 CheckedChanged 事件后面的 vb 代码中完成此操作。我可以在第四个选择时弹出消息,但无法取消选中该框。我以为 box.Checked = False 可以做到这一点,但事实并非如此。我需要对发件人做些什么吗?或者我是否接近我所拥有的?

Protected Sub CheckBoxPain_CheckedChanged(sender As Object, e As System.EventArgs)

Dim box As CheckBox
Dim numChecked As Integer = 0

For Each row As GridViewRow In gv_pain.Rows
If row.RowType = DataControlRowType.DataRow Then
box = CType(row.Cells(0).FindControl("CheckBoxPain"), CheckBox)
If box.Checked Then
numChecked = numChecked + 1
End If
End If
Next

'Response.Write("NUM:" & numChecked.ToString)
'Response.Write("STATUS:" & box.Checked.ToString)
'Response.Write("ITEM:" & box.SelectedItem.Text)

If numChecked.ToString > 3 Then
Response.Write("<script>alert('Only 3 Pain Selections allowed')</script>")
box.Checked = False
End If

End Sub

最佳答案

我通过添加 UnCheckMe 变量并获取 CType(sender, Checkbox) 解决了这个问题,如下所示:

Protected Sub CheckBoxPain_CheckedChanged(sender As Object, e As System.EventArgs)

Dim box As CheckBox
Dim numChecked As Integer = 0
Dim GridCategory As String = "Pain"

For Each row As GridViewRow In gv_pain.Rows
If row.RowType = DataControlRowType.DataRow Then
box = CType(row.Cells(0).FindControl("CheckBox" & GridCategory), CheckBox)
If box.Checked Then
numChecked = numChecked + 1
End If
End If
Next

Dim MaxChecked As String = "3"
If numChecked.ToString > MaxChecked Then
Response.Write("<script>alert('Only " & MaxChecked & " " & GridCategory & " Selections allowed, uncheck one to make a new selection.')</script>")

Dim UnCheckMe = CType(sender, CheckBox)
UnCheckMe.Checked = False
End If

End Sub

关于javascript - 取消选中后面代码中 CheckedChanged 上的最后一个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33876324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com