Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

dropdown SelectedItem.Value urgent pls.

Posted on 2004-11-11
12
Medium Priority
?
316 Views
Last Modified: 2012-05-05
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>
0
Comment
Question by:code1994
  • 6
  • 5
12 Comments
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 12557906
- 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
 

Author Comment

by:code1994
ID: 12558056
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
 

Author Comment

by:code1994
ID: 12558062
<asp:dropdownlist id="ddlBillid" style="Z-INDEX: 115; LEFT: 150px; POSITION: absolute; TOP: 270px"
                        runat="server" Width="175px"></asp:dropdownlist>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:ryerras
ID: 12558199
put the EnableViewState to true
0
 

Author Comment

by:code1994
ID: 12558289
already its true
0
 
LVL 6

Expert Comment

by:ryerras
ID: 12558348
ok. where are you binding the data to drop down list? in Page_Load? or where else?
0
 

Author Comment

by:code1994
ID: 12558438
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
 
LVL 6

Expert Comment

by:ryerras
ID: 12558530
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
 
LVL 6

Expert Comment

by:ryerras
ID: 12558542
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
 

Author Comment

by:code1994
ID: 12558550
my code is page_load


i don't have any code related with page.ispostback
0
 
LVL 6

Accepted Solution

by:
ryerras earned 500 total points
ID: 12558636
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
 

Author Comment

by:code1994
ID: 12558683
i was not using:  - thank you so much

If Not Page.IsPostBack then
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question