Wednesday, 3 May 2017

Get Selected Text and Value of CheckBoxList using jQuery in ASP.Net


Get Selected Text and Value of CheckBoxList using jQuery in ASP.Net
Description:

In this example we explain that how to get or set the text and value of the checkboxlist in asp.net using jQuery.or get selected Text and value of CheckBoxList using jQuery in asp.net.how to get selected text and value of checkboxlist control using jQuery in asp.net.
Code:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("[id*=btngetGame]").click(function () {
                var checked_checkboxes = $("[id*=chkGames] input:checked");
                var message = "";
                checked_checkboxes.each(function () {
                    var value = $(this).val();
                    var text = $(this).closest("td").find("label").html();
                    message += "Text: " + text + " Value: " + value;
                    message += "\n";
                });
                alert(message);
                return false;
            });
        });
    </script>
    <title>Get Selected Text and Value of CheckBoxList using jQuery in ASP.Net</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:CheckBoxList ID="chkGames" runat="server">
        <asp:ListItem Text="Cricket" Value="1" />
        <asp:ListItem Text="Tennis" Value="2" />
        <asp:ListItem Text="Football" Value="3" Selected="True" />
        <asp:ListItem Text="Volleyball" Value="4" />
    </asp:CheckBoxList>
    <asp:Button ID="btngetGame" Text="Get Selected Items" runat="server" />
    </form>
</body>
</html>




0 comments:

Post a Comment