dropdown SelectedItem.Value urgent pls.

i have dropdown and have some values in it and every time i select some records its keep giving me the very first
record which is "Select..."

  Dim x As String = ddlBillid.SelectedItem.Value
response.write(x)

im keep getting oly "Select..." regardless what i have select


<select name="ddlBillid" id="ddlBillingMethod" style="width:175px;Z-INDEX: 115; LEFT: 150px; POSITION: absolute; TOP: 270px">
      <option value="Select...">Select...</option>
      <option value="7">Aicense</option>
      <option value="5">Bck</option>
      <option value="6">Mcense</option>
      <option value="8">Pvey</option>
code1994Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nauman_ahmedCommented:
- Make sure that you bind your list in the following way:

if (!Page.IsPostBack)
{
   BindMyList();
}

- Make sure that your list has autopostback=true.

- Why dont you use asp.net dropdown server control?

-Nauman.
0
code1994Author Commented:
im using asp.net dropdown

if i use postback =true then whenever i select any value from dropdown it refreshing the page and it goes back to the first value.

0
code1994Author Commented:
<asp:dropdownlist id="ddlBillid" style="Z-INDEX: 115; LEFT: 150px; POSITION: absolute; TOP: 270px"
                        runat="server" Width="175px"></asp:dropdownlist>
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

ryerrasCommented:
put the EnableViewState to true
0
code1994Author Commented:
already its true
0
ryerrasCommented:
ok. where are you binding the data to drop down list? in Page_Load? or where else?
0
code1994Author Commented:
on page_load:

here is my code -- please correct me if im doing correct:


        Dim sqlConnection As SqlConnection
        Dim sqlDR As SqlDataReader
        sqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
        Dim sqlCommand As New SqlCommand("up_TSResellerSettings_Select", sqlConnection)
        sqlCommand.CommandType = CommandType.StoredProcedure

        sqlCommand.Parameters.Add("@Spflag", SqlDbType.VarChar, 100)
        sqlCommand.Parameters.Add("@spCompanyID", SqlDbType.Int, 4)
        sqlCommand.Parameters("@spFlag").Value = "BillingMethod"
        sqlCommand.Parameters("@spCompanyID").Value = Session("CompanyID")

        sqlConnection.Open()
        sqlDR = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection)

       
        If sqlDR.HasRows Then              ddlBillid.DataSource = sqlDR
            ddlBillid.DataTextField = "BillingMethod"
            ddlBillid.DataValueField = "BillingMethodID"
            ddlBillid.DataBind()
            ddlBillid.Items.Insert(0, "Select...")
        End If
        sqlDR.Close()
        sqlConnection.Close()
0
ryerrasCommented:
There is nothing wrong in the code that binds the data to the drop down. I can see it works, since you get the data in the drop down. But my question was, where is this code is in. Are you calling this code in the "if (Page.IsPostBack is nothing)" loop? or where
0
ryerrasCommented:
If you simply put it in the page_load, when you postback, your page is getting the data from the database again and adding it to the Dropdown. Which results in the first value being the selected forever
0
code1994Author Commented:
my code is page_load


i don't have any code related with page.ispostback
0
ryerrasCommented:
Well you should put the entire code in page.ispostback like this

If Not Page.IsPostBack then
  Dim sqlConnection As SqlConnection
        Dim sqlDR As SqlDataReader
        sqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
        Dim sqlCommand As New SqlCommand("up_TSResellerSettings_Select", sqlConnection)
        sqlCommand.CommandType = CommandType.StoredProcedure

        sqlCommand.Parameters.Add("@Spflag", SqlDbType.VarChar, 100)
        sqlCommand.Parameters.Add("@spCompanyID", SqlDbType.Int, 4)
        sqlCommand.Parameters("@spFlag").Value = "BillingMethod"
        sqlCommand.Parameters("@spCompanyID").Value = Session("CompanyID")

        sqlConnection.Open()
        sqlDR = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection)

       
        If sqlDR.HasRows Then              ddlBillid.DataSource = sqlDR
            ddlBillid.DataTextField = "BillingMethod"
            ddlBillid.DataValueField = "BillingMethodID"
            ddlBillid.DataBind()
            ddlBillid.Items.Insert(0, "Select...")
        End If
        sqlDR.Close()
        sqlConnection.Close()
End If

The reason for doing this is...
The data should be binded to the dropdown only when the page loads first time, not everytime it post backs
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
code1994Author Commented:
i was not using:  - thank you so much

If Not Page.IsPostBack then
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

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.