aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT
Advertise Here

Advertize

wwwSW
Posted by Aamir Hasan   on Friday, July 22, 2011 Total Views:  

In this post, we will see how to get total items from DropDownList using jQuery. We will use the button to display the total items in the Label.

Let’s say we have DropDownList like this:

        <asp:DropDownList ID="DropDownList1" runat="server">
           
<asp:ListItem Value="0">SELECT</asp:ListItem>
           
<asp:ListItem Value="1">APPLE</asp:ListItem>
           
<asp:ListItem Value="2">BANANA</asp:ListItem>
           
<asp:ListItem Value="3">ORANGE</asp:ListItem>
           
<asp:ListItem Value="4">MANGO</asp:ListItem>
       
</asp:DropDownList>

 

To find out the total items when button is clicked and display in the Label, do this:

        <input id="btnClick" type="button" value=" Click " />
       
<asp:Label ID="Label1" runat="server"></asp:Label>

 

Here is the code used to get the total items from DropDownList and display in the Label when button will be clicked.

<script type="text/javascript">

        $(function () {
            $("#btnClick").click(function () {
                var len = $("#<%=DropDownList1.ClientID %> option").length;
                $("#<%=Label1.ClientID %>").text("Total items: " + len);
            });
        });

</script>

 


Here’s an example

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.2.min.js" type="text/javascript"></script>

    <script type="text/javascript">

        $(function () {

            $("#btnClick").click(function () {

                var len = $("#<%=DropDownList1.ClientID %> option").length;

                $("#<%=Label1.ClientID %>").text("Total items: " + len);

            });

        });

    </script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:DropDownList ID="DropDownList1" runat="server">

            <asp:ListItem Value="0">SELECT</asp:ListItem>

            <asp:ListItem Value="1">APPLE</asp:ListItem>

            <asp:ListItem Value="2">BANANA</asp:ListItem>

            <asp:ListItem Value="3">ORANGE</asp:ListItem>

            <asp:ListItem Value="4">MANGO</asp:ListItem>

        </asp:DropDownList>

        <br />

        <input id="btnClick" type="button" value=" Click " />

        <asp:Label ID="Label1" runat="server"></asp:Label>

    </div>

    </form>

</body>

</html>


Output

Download

DropDownList-total-items-count.rar (673.00 bytes)

See live demo

Protected by Copyscape Online Plagiarism Tool

Comments (2) -

windows 7 key
windows 7 key United States
3/7/2012 8:40:15 PM #

I am using Windows XP and I am considering getting windows 7 http://www.windows7ultimateproductkey.org/
windows 7 key http://www.windows7ultimateproductkey.org/
windows 7 ultimate http://www.windows7ultimateproductkey.org/
windows 7 ultimate product key http://www.windows7ultimateproductkey.org/

fafafa
fafafa Slovenia
4/23/2012 2:15:08 AM #

http://www.christianlouboutinukk.org   christian louboutin
http://www.tiffanyuks.org   tiffany uk
http://www.gucciukbeltuk.org   gucci belt
http://www.frsaclouisvuittonsac.com   louis vuitton sac
http://www.chanelukoutletuks.org   chanel outlet
http://www.burberryukoutletuk.org   burberry
http://www.poloralphlaurenuko.org   ralph lauren uk

feel
feel People's Republic of China
5/2/2012 11:42:11 PM #


Cheap NFL,NBA,MLB,NHL [url=http://www.annajerseys.com/]China Jerseys[/url],[url=http://www.annajerseys.com/]China Jerseys Paypal[/url] For Sale online.[url=www.annajerseys.com/...ke-nfl-jerseys-c-1_478.html]2012 Nike NFL Jerseys[/url],All Our Jerseys Are Sewn On and Directly From [url=www.annajerseys.com/...d-patriots-c-1_478_498.html]Nike New England Patriots Jerseys[/url] Factory2012 [url=www.annajerseys.com/.../...fl-jerseys-c-1_478.html]Nike NFL Jerseys China[/url] Wholesale,Wholesale [url=www.annajerseys.com/...falo-bills-c-1_478_482.html]Nike Buffalo Bills Jerseys[/url] From,The high quality Nike NFL Jerseys are  [url=www.annajerseys.com/...oston-bruins-c-124_133.html]Boston Bruins Jerseys[/url] great gifts [url=www.annajerseys.com/...o-blackhawks-c-124_137.html]Chicago Blackhawks Jerseys China[/url] for Arizona Cardinals  [url=www.annajerseys.com/...e-seahawks-c-1_478_507.html]Nike Seattle Seahawks Jerseys[/url].Welcome to our [url=http://www.annajerseys.com/]http://www.annajerseys.com/[/url] to pick [url=www.annajerseys.com/...hia-eagles-c-1_478_503.html]Nike Philadelphia Eagles Jerseys[/url] the hotest [url=www.annajerseys.com/.../...fl-jerseys-c-1_478.html]2012 New NFL Jerseys[/url].
[/pre]

  Best Converse Online Store From UK,Sale 2011 Newest [url=www.sale-converse.com/...rse-flag-shoes-c-130.html]Converse Flag Shoes[/url],Black Converse,[url=www.sale-converse.com/...ewest-converse-c-135.html]Converse 2012[/url],[url=http://www.sale-converse.com/]Cheap Converse[/url] Navy Converse And So on [url=www.sale-converse.com/...-hitop-uk-flag-p-899.html]Converse 2011 All Star Shoes Hi-top UK Flag[/url],[url=http://www.sale-converse.com/]Converse UK[/url],[url=www.sale-converse.com/...rica-flag-red-p-1037.html]Converse 2011 All Star Shoes Hi-top America Flag Red[/url]Free Shipping
[/pre]

We are professional jerseys manufacturer from china,wholesal sports [url=http://www.anna-jersey.com/nfl-jerseys-c-773.html]NFL jerseys China[/url],[url=http://www.anna-jersey.com/nhl-jerseys-c-882.html]NHL Jerseys China[/url],[url=http://www.anna-jersey.com/nba-jerseys-c-821.html]NBA Jerseys China[/url],[url=http://www.anna-jersey.com/mlb-jerseys-c-694.html]MLB Jerseys China[/url],[url=http://www.anna-jersey.com/]China Jerseys[/url],  [url=www.anna-jersey.com/...nike-nfl-jerseys-c-943.html]2012 Nike NFL Jerseys[/url],[url=www.anna-jersey.com/...chicago-cubs-c-694_702.html]Chicago Cubs Jerseys China[/url], Free Shipping
[/pre]
[pre]
,[url=http://www.china4jersey.com/nhl-jerseys-c-512.html]NHL Jerseys China[/url] Paypal,[url=http://www.china4jersey.com/]China Jerseys Paypal[/url] factory,Sewn On Jerseys,Accept Paypal,Free Shipping,[url=www.china4jersey.com/nike-nfl-2012-c-638.html]Nike NFL Jerseys Paypal[/url]   ,Nike Jerseys,[url=www.china4jersey.com/nike-nfl-2012-c-638.html]NFL Jerseys 2012[/url],[url=www.china4jersey.com/nike-nfl-2012-c-638.html]Nike Jerseys China[/url],[url=www.china4jersey.com/nike-nfl-2012-c-638.html]Wholesale Nike Jerseys China[/url][url=http://www.nikenflchina.com/]Nike NFL Jerseys[/url],[url=http://www.nikenflchina.com/]New NFL Jerseys 2012[/url],[url=http://www.nikenflchina.com/]Nike NFL Jerseys China[/url],[url=www.nikenflchina.com/...nike-nfl-jerseys-c-73.html]2012 Nike NFL Jerseys[/url],[url=www.china4jersey.com/...ton-red-sox-c-398_401.html]Boston Red Sox[/url]Professional Online Wholesale Shop From China,We are Chinese Jerseys Manufactruer,Wholesale All Team Of Nike NFL Jerseys,2012 New NFL Jeresys,NFL Jerseys China,Nike Jerseys China,New NFL Jerseys,All Jerseys are embroidered on,Free Shipping To World Wide
[/pre]

Professional Converse Online Store From UK,[url=http://www.converse2you.com/]Converse UK[/url] Shop,Sale 2012 Newest Converse All Stars,Converse Flag Shoes,[url=http://www.converse2you.com/]Cheap Converse[/url],[url=http://www.converse2you.com/]Converse Sale[/url],[url=www.converse2you.com/index.php]Converse Flag Shoes[/url] ,[url=www.converse2you.com/index.php]New Converse 2012[/url] Free Shipping To World Wide.
[/pre]

fake oakley sunglasses
fake oakley sunglasses Nigeria
5/6/2012 11:18:52 PM #

http://www.oakley-glasses2012.com fake oakley sunglasses
We have the oakley sunglasses discount-www.oakley-glasses2012.com/...s-discount_c-27.html, although it is the best fake oakley sunglasses-http://www.oakley-glasses2012.com arequality, we have fake Oakley sprots sunglasses-www.oakley-glasses2012.com/...asses_c-29.html,fake Oakley lifestyle sunglasses-www.oakley-glasses2012.com/...asses_c-30.html,fake Oakley active sunglasses-www.oakley-glasses2012.com/...asses_c-31.html,fake Oakley polarized sunglasses-www.oakley-glasses2012.com/...lasses_c-32.html,Our new oakley sunglasses-www.oakley-glasses2012.com/...asses-2012_c-33.html have oakley sunglasses 2012-www.oakley-glasses2012.com/.../...45_p-298075.html

Pingbacks and trackbacks (2)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5