Home > Forum > ASP.NET > How to get dropdownlist selected item value in asp.net

How to get dropdownlist selected item value in asp.net

by Thamil   on Oct 10, 2014   Category: ASP.NET  |  Views: 47566    |  Points: 5   |  Gold 

Iam working with asp.net dropdownlist iam using 3 dropdownlits like class,subject,chapter iam using jquery to bind drpdownlists iam fine with binding but when i want to insert in to database drpdownlist selected item not getting ima getting like selected subject and selected chapter only iam hving list of items in dropdownlist.

but iam unable to inserting

Question posted on behalf of dineshkumar.

Bookmark and Share:
  User Reply  | Ask a question  |   Reply 
  Re :How to get dropdownlist selected item value in asp.net   
by Thamil
on Oct 10 2014 6:23AM
Points : 10
hi dineshkumar,

Below sample code shows how to get selected value and selected item from dropdown list control.
<asp:DropDownList ID="ddlMonth" Width="200px" runat="server">
<asp:ListItem Value="0">--Select--</asp:ListItem>
<asp:ListItem Value="1">January</asp:ListItem>
<asp:ListItem Value="2">February</asp:ListItem>
<asp:ListItem Value="3">March</asp:ListItem>
<asp:ListItem Value="4">April</asp:ListItem>
<asp:ListItem Value="5">May</asp:ListItem>
<asp:ListItem Value="6">June</asp:ListItem>
<asp:ListItem Value="7">July</asp:ListItem>
<asp:ListItem Value="8">August</asp:ListItem>
<asp:ListItem Value="9">September</asp:ListItem>
<asp:ListItem Value="10">October</asp:ListItem>
<asp:ListItem Value="11">November</asp:ListItem>
<asp:ListItem Value="12">December</asp:ListItem>
</asp:DropDownList><br /><br />
<asp:Button ID="btnGetMonth" runat="server" Text="Get Month"
onclick="btnGetMonth_Click" /><br /><br />
Selected Value : <asp:Label ID="lblMonthVal" runat="server" Text="Label"></asp:Label><br />
Selected Item : <asp:Label ID="lblMonthItem" runat="server" Text="Label"></asp:Label>

code behind part:
protected void btnGetMonth_Click(object sender, EventArgs e)
lblMonthVal.Text = ddlMonth.SelectedValue;
lblMonthItem.Text = ddlMonth.SelectedItem.Text;

ddlMonth.SelectedValue returns the value of selected item in dropdown control ex if you select January from dropdown list then Selected Value would be 1 and selected item would be January.
I hope this will help you.
  Re :How to get dropdownlist selected item value in asp.net   
by ankitha
on Mar 21 2016 8:39AM
Points : 10

follow the link above if you have any doubts it is explained easily here using a video

Recent Post

Latest Posts