选中Gridview里checkbox值,根据选中情况进行判断: 如果没有选中任何一项,则弹出一个对话框提醒 "请选择要
2个回答
展开全部
用js吧
<script type="text/javascript">
function ValidateCheckbox() {
var chks = document.getElementsByName("GVchk");
var result = "";
for (var i = 0; i < chks.length; i++) {
if (chks[i].checked) {
result += chks[i].value + ",";
}
}
if (result.length <= 0) {
alert("请选择");
return false;
} else {
if (confirm("要删除吗?")) {
document.getElementById("HiddenField1").value = result;//删除项目的ID,保存在隐藏域中,后台好读取 结果例如:1,2,3,5,7,
return true;
} else {
return false;
}
}
}
</script>
前台部分
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="del" OnClientClick="return ValidateCheckbox()" />
<asp:GridView ID="GridView1" runat="server" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="checkbox" name="GVchk" value='<%#Eval("t_id") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<script type="text/javascript">
function ValidateCheckbox() {
var chks = document.getElementsByName("GVchk");
var result = "";
for (var i = 0; i < chks.length; i++) {
if (chks[i].checked) {
result += chks[i].value + ",";
}
}
if (result.length <= 0) {
alert("请选择");
return false;
} else {
if (confirm("要删除吗?")) {
document.getElementById("HiddenField1").value = result;//删除项目的ID,保存在隐藏域中,后台好读取 结果例如:1,2,3,5,7,
return true;
} else {
return false;
}
}
}
</script>
前台部分
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="del" OnClientClick="return ValidateCheckbox()" />
<asp:GridView ID="GridView1" runat="server" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input type="checkbox" name="GVchk" value='<%#Eval("t_id") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询