Tuesday, October 6, 2015

Read Xml data and display Jquary

<?xml version="1.0" encoding="utf-8" ?>
        <booklist>
            <book>
                <title>Naresh</title>
                <author>Naresh1</author>
                <genre>Classic</genre>
            </book>
            <book>
                <title>abc</title>
                <author>def</author>
                <genre>Classic</genre>
            </book>
            <book>
                <title>qqq</title>
                <author>asd</author>
                <genre>www</genre>
            </book>
          
        </booklist>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script>
            $(document).ready(function () {
                $("#contentArea").append("<ul></ul>");
                $.ajax({
                    type: "GET",
                    url: "data.xml",
                    dataType: "xml",
                    success: function (xml) {
                        $(xml).find('Book').each(function () {
                            var sTitle = $(this).find('Title').text();
                            var sAuthor = $(this).find('Author').text();
                            var sGenre = $(this).find('Genre').text();
                            $("<li></li>").html(sTitle + ", " + sAuthor + "," + sGenre).appendTo("#contentArea ul");
                        });
                    },
                    error: function () {
                        alert("An unexpected error has occurred during processing.");
                    }
                });
            });
        </script>

     
        <div id="contentArea">

        </div>

Validate Listbox Ckeckbox Abd Radio Buttons

<asp:ListBox ID="ListBox1" runat="server" Rows="6" SelectionMode="Multiple">
            <asp:listitem text="India" value="1"></asp:listitem>
            <asp:listitem text="US" value="2"></asp:listitem>
            <asp:listitem text="UK" value="3"></asp:listitem>
            <asp:listitem text="China" value="4"></asp:listitem>
            <asp:listitem text="Russia" value="5"></asp:listitem>
            <asp:listitem text="New Zealand" value="6"></asp:listitem>
        </asp:ListBox>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Required two country" ClientValidationFunction="Validate_ListBox"></asp:CustomValidator>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" /><asp:ListBox ID="ListBox1" runat="server" Rows="6" SelectionMode="Multiple">
            <asp:listitem text="India" value="1"></asp:listitem>
            <asp:listitem text="US" value="2"></asp:listitem>
            <asp:listitem text="UK" value="3"></asp:listitem>
            <asp:listitem text="China" value="4"></asp:listitem>
            <asp:listitem text="Russia" value="5"></asp:listitem>
            <asp:listitem text="New Zealand" value="6"></asp:listitem>
        </asp:ListBox>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Required two country" ClientValidationFunction="Validate_ListBox"></asp:CustomValidator>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
        <script>
            function Validate_ListBox(sender, args) {
                var Listoptions = document.getElementById("<%=ListBox1.ClientID%>").options;
                var Selectedcount = 0;
                for (var i = 0; i < Listoptions.length; i++) {
                    if (Listoptions[i].selected == true) {
                        Selectedcount++;
                    }
                }
                if (Selectedcount <= 2) {
                    args.IsValid = false;
                } else {
                    args.IsValid = true;
                }
            }
        </script>


        /////////////////////////////////////////////
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script>
            function CheckBoxList1_Validation(sender, args) {
                args.IsValid = false;
                var cnt = $("#CheckBoxList1 input:checked").length;
                args.IsValid = (cnt >= 2);
            }
        </script>
        Select at least 2 countries:
        <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:listitem text="India" value="1"></asp:listitem>
            <asp:listitem text="US" value="2"></asp:listitem>
            <asp:listitem text="UK" value="3"></asp:listitem>
            <asp:listitem text="China" value="4"></asp:listitem>
            <asp:listitem text="Russia" value="5"></asp:listitem>
            <asp:listitem text="New Zealand" value="6"></asp:listitem>
        </asp:CheckBoxList>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select at least 2 countries" ClientValidationFunction="CheckBoxList1_Validation" ForeColor="Red"></asp:CustomValidator>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />


        ///////////////////////////////////////////////////////
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script>
            function RadioButtonList1_Validate(sender, args) {
                args.IsValid = ($("#RadioButtonList1 :radio:checked").length > 0);
            }
        </script>
        <asp:RadioButtonList ID="RadioButtonList1" runat="server">
           <asp:listitem text="India" value="1"></asp:listitem>
            <asp:listitem text="US" value="2"></asp:listitem>
            <asp:listitem text="UK" value="3"></asp:listitem>
            <asp:listitem text="China" value="4"></asp:listitem>
            <asp:listitem text="Russia" value="5"></asp:listitem>
            <asp:listitem text="New Zealand" value="6"></asp:listitem>
        </asp:RadioButtonList>
        <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please select a country" Display="Dynamic" ClientValidationFunction="RadioButtonList1_Validate" ForeColor="Red"></asp:CustomValidator>
        <br />

        <asp:Button ID="btnSubmit" runat="server" Text="Submit" />