This
article will show how you can get the dropdown list text value of selected item
using jQuery in asp.net.
<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.
0 comments:
Please let me know your view