asp.net - dropdown doesnt return the value the user clicks on...

I have a dropdownlist that lists the states....yet when the user clicks a state...that value doesn't post...
LVL 10
GlobaLevelProgrammerAsked:
Who is Participating?
 
Rose BabuSenior Team ManagerCommented:
Hi,

in your design and code page try the following snippet

Design:
Set AutoPostBack=true for that dropdownlist

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
</asp:DropDownList>

Open in new window


Code:
getting selected data from dropdownlist

VB:
Sub Page_Load
    If Not IsPostBack
        Dim state as string =  "Selected Text: " _
        & ddlState.SelectedItem.Text & " Selected Value: " _
        & ddlState.SelectedItem.Value & " Selected Index: " _
        & ddlState.SelectedIndex   
    End If
End Sub

Open in new window

C#:
public void Page_Load()
{
	if (!IsPostBack) {
		string state = "Selected Text: " + ddlState.SelectedItem.Text;
		state += " Selected Value: " + ddlState.SelectedItem.Value; 
		state += "<BR>Selected Index: " + ddlState.SelectedIndex;
	}
}

Open in new window



Happy Programming.
0
 
GlobaLevelProgrammerAuthor Commented:
its a postback issue it gets written over on postbakc and I cant remember how to solve
0
 
SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
Hello, You should change the property IsPostBack = Enable
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.