如何制作“全选”在sumoselect jquery的页面加载上默认选中 [英] How to make the "select all" checked by default on page load for sumoselect jquery

查看:91
本文介绍了如何制作“全选”在sumoselect jquery的页面加载上默认选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Sumoselect jquery填充ASP.Net WebForms页面中的下拉列表,但是在页面加载时我无法选中全选选项,以便在页面加载时选择所有下拉列表值。



我尝试了什么:



这是我的aspx代码 - -



I am using Sumoselect jquery for populating the dropdown list in my ASP.Net WebForms page, but on page load I am unable to make the selection "Select All" checked so that all the dropdowns values were being selected on page load.

What I have tried:

This is my aspx code---

<%@ Page Language="C#" AutoEventWireup="true" Inherits="Dropdown1" CodeBehind="Dropdown1.aspx.cs" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script type="text/javascript" src="jquery.sumoselect.min.js"></script>
    <link href="sumoselect.css" rel="stylesheet" />

    <script type="text/javascript">

        $(document).ready(function () {
            $('#<%=lstBoxTest.ClientID%>').SumoSelect({selectAll:true});
        });


    </script>
    <style type="text/css">
        body {
            font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
            color: #444;
            font-size: 13px;
        }

        p, div, ul, li {
            padding: 0px;
            margin: 0px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ListBox runat="server" ID="lstBoxTest" SelectionMode="Multiple">
            <asp:ListItem Text="Red" Value="0"></asp:ListItem>
            <asp:ListItem Text="Green" Value="1"></asp:ListItem>
            <asp:ListItem Text="Yellow" Value="2"></asp:ListItem>
            <asp:ListItem Text="Blue" Value="3"></asp:ListItem>
            <asp:ListItem Text="Black" Value="4"></asp:ListItem>
        </asp:ListBox>
        <asp:Button Text="Get Values" Visible="false" ID="btnGetSelectedValues" OnClick="btnGetSelectedValues_Click" runat="server" />
    </form>
</body>
</html>











这是我的代码---








and this is my code behind---

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


    public partial class Dropdown1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


        }


        protected void btnGetSelectedValues_Click(object sender, EventArgs e)
        {
            string selectedValues = string.Empty;



            foreach (ListItem li in lstBoxTest.Items)
            {
                if (li.Selected == true)
                {
                    selectedValues += li.Text + ",";
                }
            }

            
            Response.Write(selectedValues.ToString());
        }



    }

推荐答案

(文件)。 ready(function(){
(document).ready(function () {


('#<%= lstBoxTest.ClientID%>')。SumoSelect({selectAll:true});
});


< / script>
< style type =text / css>
body {
font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;
颜色:#444;
字体大小:13px;
}

p,div,ul,li {
padding:0px;
保证金:0px;
}
< / style>
< / head>
< body>
< form id =form1runat =server>
< asp:ListBox runat =serverID =lstBoxTestSelectionMode =Multiple>
< asp:ListItem Text =RedValue =0>< / asp:ListItem>
< asp:ListItem Text =GreenValue =1>< / asp:ListItem>
< asp:ListItem Text =YellowValue =2>< / asp:ListItem>
< asp:ListItem Text =BlueValue =3>< / asp:ListItem>
< asp:ListItem Text =BlackValue =4>< / asp:ListItem>
< / asp:ListBox>
< asp:Button Text =Get ValuesVisible =falseID =btnGetSelectedValuesOnClick =btnGetSelectedValues_Clickrunat =server/>
< / form>
< / body>
< / html>
('#<%=lstBoxTest.ClientID%>').SumoSelect({selectAll:true}); }); </script> <style type="text/css"> body { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #444; font-size: 13px; } p, div, ul, li { padding: 0px; margin: 0px; } </style> </head> <body> <form id="form1" runat="server"> <asp:ListBox runat="server" ID="lstBoxTest" SelectionMode="Multiple"> <asp:ListItem Text="Red" Value="0"></asp:ListItem> <asp:ListItem Text="Green" Value="1"></asp:ListItem> <asp:ListItem Text="Yellow" Value="2"></asp:ListItem> <asp:ListItem Text="Blue" Value="3"></asp:ListItem> <asp:ListItem Text="Black" Value="4"></asp:ListItem> </asp:ListBox> <asp:Button Text="Get Values" Visible="false" ID="btnGetSelectedValues" OnClick="btnGetSelectedValues_Click" runat="server" /> </form> </body> </html>











这是我的代码---








and this is my code behind---

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


    public partial class Dropdown1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


        }


        protected void btnGetSelectedValues_Click(object sender, EventArgs e)
        {
            string selectedValues = string.Empty;



            foreach (ListItem li in lstBoxTest.Items)
            {
                if (li.Selected == true)
                {
                    selectedValues += li.Text + ",";
                }
            }

            
            Response.Write(selectedValues.ToString());
        }



    }


查看文档 [ ^ ],您需要调用 selectAll 方法:

Looking at the documentation[^], you need to call the selectAll method:


这篇关于如何制作“全选”在sumoselect jquery的页面加载上默认选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆