1

Dim zonename As String = DropDownList1.SelectedItem.Text

It always display the first value from the dropdownlist

4
  • You mean something like array? Commented Apr 4, 2013 at 6:20
  • I m using dropdownlist in web page and in page_load event it is filled from sql database now i want to select the particular value from the list but after selecting the value and click on save_bt_event the above code always displays the first value of the dropdownlist Commented Apr 4, 2013 at 6:23
  • Did u try doing that with selectedvalue? Commented Apr 4, 2013 at 6:24
  • assing the value of dropdownlist to string in SelectedItem_changed() event. Commented Apr 4, 2013 at 6:24

2 Answers 2

2

try it binding in is not postback
Reference

If you bind inside page load you will always get the first value of the dropdown list.

private void Page_Load()
{
   if (!IsPostBack)
   {
        //bind your dropdown here
   }
}

In VB

Sub Page_Load
  If Not IsPostBack
    ' bind your dropdown list
    Validate()
  End If
End Sub

Edit 1

Storing Connection string you can use web.config file

http://www.connectionstrings.com/Articles/Show/store-connection-string-in-web-config

Sign up to request clarification or add additional context in comments.

2 Comments

okay help me for another problem.... I want to use global page in vb.net for asp.net for my global variables like connection string, user sessions.... how to do this
Ideally you should put another question here. But You should use web.config for connection-string file for this. Also there is gloabal.asax which can help you.
0

use page.ispostback

within page load event...

if NOT page.isPostBack Then
Dim zonename As String = DropDownList1.SelectedItem.Text
End if

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.