gpt4 book ai didi

c# - JQuery勾选项CheckBoxList

转载 作者:行者123 更新时间:2023-11-30 19:41:50 27 4
gpt4 key购买 nike

我尝试在用户控件中使用 JQuery 客户端检查 CheckBoxList 中的特定项目?

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:AppCon %>"
SelectCommand="SELECT DesF, val, DesGrpId FROM dbo.tblDes WHERE (DesGrpId = @DesGrpId)">
</asp:SqlDataSource>

<asp:CheckBoxList ID="CheckBoxList1" runat="server" DataTextField="DesF" DataValueField="val"
DataSourceID="SqlDataSource1">

最佳答案

服务器端控制:

<asp:CheckBoxList ID="ChkList" runat="server">
<asp:ListItem Text ="a" Value="1"></asp:ListItem>
<asp:ListItem Text ="b" Value="2"></asp:ListItem>
<asp:ListItem Text ="c" Value="3"></asp:ListItem>
</asp:CheckBoxList>

客户端代码:

<script type="text/javascript">
$(function () {
var str = "1,2";
var list = $('#<%= ChkList.ClientID%> input');
list.each(function (index) {
item = $(this);
if (str.indexOf(item.val()) != -1) {
item.attr('checked', true);
}
});
});
</script>

关于c# - JQuery勾选项CheckBoxList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18672040/

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