connectseekers.com

Friday, 14 April 2017

How to Get Dropdown Selected Text in jQuery in Asp.net

4/14/2017 - By Pranav Singh 0

This article will show how you can get the dropdown list text value of selected item using jQuery in asp.net.

So for this article we will first we will create a new asp.net application and add the below code.


            <asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="219px">
                <asp:ListItem Value="1">Item 1</asp:ListItem>
                <asp:ListItem Value="2">Item 2</asp:ListItem>
                <asp:ListItem Value="3">Item 3</asp:ListItem>
            </asp:DropDownList>
            <br />
            <br />
            <input type="button" value="Get Text Value" />

Now we will write the code to get the dropdown list selected item text value.

        $(function () {
            $("#btnSubmit").click(function (event) {
                var textvalue = $("#<%=DropDownList1.ClientID %> option:selected").text();
                alert(textvalue);
            });
        });

In above code just check the hilieghted part of the code. This is used for getting the text value. Now check the complete code of the page.

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Get Dropdown Selected Text in jQuery Asp.Net</title>
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script>
        $(function () {
            $("#btnSubmit").click(function (event) {
                var textvalue = $("#<%=DropDownList1.ClientID %> option:selected").text();
                alert(textvalue);
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <asp:DropDownList ID="DropDownList1" runat="server" Height="25px" Width="219px">
                <asp:ListItem Value="1">Item 1</asp:ListItem>
                <asp:ListItem Value="2">Item 2</asp:ListItem>
                <asp:ListItem Value="3">Item 3</asp:ListItem>
            </asp:DropDownList>
            <br />
            <br />
            <input type="button" value="Get Text Value" id="btnSubmit"/>
        </div>
    </form>
</body>
</html>

Now we have done run the page to check the output.




About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Design By:
back to top