Andi03 Posted October 16, 2003 Posted October 16, 2003 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? Quote
Moderators Robby Posted October 16, 2003 Moderators Posted October 16, 2003 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 ..." Quote Visit...Bassic Software
Andi03 Posted October 16, 2003 Author Posted October 16, 2003 (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 October 16, 2003 by Andi03 Quote
Moderators Robby Posted October 16, 2003 Moderators Posted October 16, 2003 no, don't Use Exit Sub, try this instead.. 'place this in your page load event If not ispostback then LoadDropdownFunction() end if Quote Visit...Bassic Software
Andi03 Posted October 16, 2003 Author Posted October 16, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.