我的表格中可以有任意数量的复选框。
<input type="checkbox" value='<%#Eval("MapID") %>' class="chk" runat="server"/>
...
那么如何从后面的代码中将所有复选框设置为false?
<asp:UpdatePanel runat="server" ID="AccesUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:ListView ID="lvCurrentMaps" runat="server" >
<LayoutTemplate>
<table cellpadding="0" cellspacing="0" border="0" class="display rndCorner2" id="example" width="100%">
<thead>
<tr id="Tr1" runat="server" class="itemTableHeader">
<td>
<asp:Label runat="server" ID="Label1" Text="Select" />
</td>
<td id="Td1" runat="server">
<asp:Label runat="server" ID="lblMapID" Text="Map ID" />
</td>
</tr>
</thead>
<tbody>
<tr id="itemPlaceholder" runat="server">
</tr>
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server" class="itemTableData">
<td id="Td6" runat="server" class="chkbox">
<input type="checkbox" value='<%#Eval("MapID") %>' class="chk" runat="server"/>
</td>
<td id="Td1" runat="server" onclick='<%#"doPostBackForView("+Eval("MapID")+")" %>' style="cursor:pointer !important">
<asp:Label runat="server" ID="lblIDMapValue" Text= '<%#Eval("MapID") %>' />
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr id="Tr2" runat="server" class="altItemTableData">
<td id="Td6" runat="server" class="chkbox">
<input id="Checkbox" type="checkbox" value='<%#Eval("MapID") %>' class="chk" runat="server"/>
</td>
<td id="Td1" runat="server" onclick='<%#"doPostBackForView("+Eval("MapID")+")" %>' style="cursor:pointer !important">
<asp:Label runat="server" ID="lblIDMapValue" Text= '<%#Eval("MapID") %>' />
</td>
<td id="Td8" runat="server" onclick='<%#"doPostBackForView("+Eval("MapID")+")" %>' style="cursor:pointer !important">
<asp:Label runat="server" ID="lblMapNameValue" Text= '<%#Eval("MapName") %>' />
</td>
<td id="Td9" runat="server" onclick='<%#"doPostBackForView("+Eval("MapID")+")" %>' style="cursor:pointer !important">
<asp:Label runat="server" ID="lblMapDescValue" Text= '<%#Eval("MapDesc") %>' />
</td>
</tr>
</AlternatingItemTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
我正在尝试类似的事情:
foreach(var li in lvCurrentMaps.Items)
{
li.DataItem = false;
}
AccesUpdatePanel.Update();
任何想法? 可能通过ScriptManager?
答案 0 :(得分:0)
Jquery解决方案:
<script type="text/javascript">
$(document).ready(function(){
$('.chk').prop('checked', false);
});
</script>
答案 1 :(得分:0)
试试这个
<input type="checkbox" Checked='<%# Eval("MapID") %> class="chk" runat="server"/>
如果数据列MapID的值不是布尔值,请尝试使用
创建方法
public bool CheckMapID(object mapID)
{
if (mapID == null)
{
return false;
}
return true;
}
并用此
替换HTML / ASPX代码<input type="checkbox" Checked=<%# CheckMapID(Eval("MapID")) %> class="chk" runat="server"/>