aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JQuery get dropdown selected value and text in

Sep 1, 2012

Here I will explain how to get dropdownlist selected value or selected item text using JQuery in

In previous articles I explained How to bind dropdownlist using JQuery and many articles relating to JQuery. Now I will explain how to get dropdownlist selected value using JQuery in

If we want to get dropdownlist selected value or selected item text in JQuery we need to write the code like as shown below

$(document).ready(function() {
//Dropdownlist Selectedchange event
$('#ddlCountry').change(function() {
// Get Dropdownlist seleted item text
$("#lbltxt").text($("#ddlCountry option:selected").text());
// Get Dropdownlist selected item value
return false;
If you want check this code in sample first design table in database and give name as Country as shown below

Column Name
Data Type
Allow Nulls
int(set identity property=true)
After completion table design enter some of Country details in database to work for our sample after that write the following code in your aspx page

<html xmlns="">
<head id="Head1" runat="server">
<title>Get Dropdownlist selected text or value using JQuery</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(document).ready(function() {
type: "POST",
contentType: "application/json; charset=utf-8",
url: "JQueryGetDropdownSelectedvalue.aspx/BindDatatoDropdown",
data: "{}",
dataType: "json",
success: function(data) {
$.each(data.d, function(key, value) {
error: function(result) {
//Dropdownlist Selectedchange event
$('#ddlCountry').change(function() {
// Get Dropdownlist seleted item text
$("#lbltxt").text($("#ddlCountry option:selected").text());
// Get Dropdownlist selected item value
return false;
<form id="form1" runat="server">
<tr><td align="right">Select Country:</td>
<td><asp:DropDownList ID="ddlCountry" runat="server" /></td>
<tr><td align="right">Selected Text:</td>
<td><b><label id="lbltxt" /></b></td>
<tr><td align="right">Selected text value:</td>
<td><b><label id="lblid" /></b></td>
If you observe above code in header section I added script file link by using that file we have a chance to interact with JQuery. If you want to know about script function mentioned in header section check these posts JQuery AutoComplete textbox with database in and call page methods in JQuery.

Now open code behind file and add following namespaces

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
After that write the following code

C#.NET Code

protected void Page_Load(object sender, EventArgs e)

public static CountryDetails[] BindDatatoDropdown()
DataTable dt = new DataTable();
List<CountryDetails> details = new List<CountryDetails>();

using (SqlConnection con = new SqlConnection("Data Source=SureshDasari;Initial Catalog=MySampleDB;Integrated Security=true"))
using (SqlCommand cmd = new SqlCommand("SELECT CountryID,CountryName FROM Country", con))
SqlDataAdapter da = new SqlDataAdapter(cmd);
foreach (DataRow dtrow in dt.Rows)
CountryDetails country = new CountryDetails();
country.CountryId = Convert.ToInt32(dtrow["CountryId"].ToString());
country.CountryName = dtrow["CountryName"].ToString();
return details.ToArray();
public class CountryDetails
public int CountryId { get; set; }
public string CountryName { get; set; }
VB.NET Code:

Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services

Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

End Sub
<WebMethod()> _
Public Shared Function BindDatatoDropdown() As CountryDetails()
Dim dt As New DataTable()
Dim details As New List(Of CountryDetails)()

Using con As New SqlConnection("Data Source=SureshDasari;Initial Catalog=MySampleDB;Integrated Security=true")
Using cmd As New SqlCommand("SELECT CountryID,CountryName FROM Country", con)
Dim da As New SqlDataAdapter(cmd)
For Each dtrow As DataRow In dt.Rows
Dim country As New CountryDetails()
country.CountryId = Convert.ToInt32(dtrow("CountryId").ToString())
country.CountryName = dtrow("CountryName").ToString()
End Using
End Using
Return details.ToArray()
End Function
Public Class CountryDetails
Public Property CountryId() As Integer
Return m_CountryId
End Get
Set(ByVal value As Integer)
m_CountryId = Value
End Set
End Property
Private m_CountryId As Integer
Public Property CountryName() As String
Return m_CountryName
End Get
Set(ByVal value As String)
m_CountryName = Value
End Set
End Property
Private m_CountryName As String
End Class
End Class

Download sample code attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

good one

Kim said...

I try your way by using JQuery in and it's really helpful.

Anonymous said...

sir i m creating dropdown dynamically and bindinded it to the database but how to make default value --Select-- and how to remove selected dropdown value from next coming dropdown.
Thanks in advance

Anonymous said...

Thank you very much ! Saved my day !

Cheers from Brazil.

Anonymous said...

Thanks very much, very helpful

Unknown said...

for what purpose u were used webmethod pls wxplain that

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.