Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi

 

I have a DroipDownlist on my page wish I load my artists in.

I use this code to do that:

 

Dim Conn As New OLEDBConnection(dbPath)
Dim tempSQL As String = "SELECT * FROM tblArtists ORDER BY titel"
Dim Cmd As New OLEDBCommand(tempSQL, Conn)
Conn.Open()
DDLartists.DataSource = Cmd.ExecuteReader()
DDLartists.DataBind()
Conn.Close()

'And the drop down list control on my pages look like this:
<asp:dropdownlist ID="DDLartists" DataTextField="name" DataValueField="artistID" runat="server" />

teh text thats showing in the dropdownlist are the artists name and its value is given from the artistID.

The When I execute the page all my artist are loaded into the dropdownlist. But when I fire my submit button and want to retriev the selected value I always get the number 4, every time. But in my database alla my artist have unique numbers (prim key)

 

I use this code to retrieve the selected value:

dim temp as string = DDLartists.SelectedItem.Value

 

Why does it always return the number 4?

 

Can some one help me?

  • Moderators
Posted

Is that code called every time you load the page? or do you check for IsPostBack?

 

Also, you might want to get rid of the "SELECT * FROM..." and try this instead ..."SELECT artistID, name FROM ..."

Visit...Bassic Software
Posted (edited)

I just load it every time

 

Edit:

You gave me a hint with the Postback thingie... I made a if-selecten if the page is post back the exit sub. And now it works.

Thanx

Edited by Andi03
Posted

well the dropdownlist its in its own sub and I puted the If Page.IsPostBack Then Exit Sub in it så its the same.

 

But I will keep it in mind.

 

Thanx again

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...