Dropdown lists

  • Thread starter Thread starter Sara
  • Start date Start date
S

Sara

Hi-

I have created a dropdown list in my VB.net application, with data from
a database table - that works fine. I then added a record to a table
through a form that has this drop down list - that worked fine too. The
problem is now selecting and displaying this value. All the other
fields are displayed fine, but the drop down list comes out blank - any
idea as to what I am doing wrong?

Thanks
 
- When you populate the ddlist the first time you are probably doing it in
the form_load event when not-is-post-back. You then display the form with the
DDList ok.
- When you use the DDList to select the item you want to select you are
either using an auto-post-back or you are selecting a
submit-button-of-some-kind. You are then posting to the server.
- In this case the aspx page is first loaded again (form_load() is run).
This is where you should be using the is-post-back part of code to get the
value of the DDList. At this point, if enable-viewstate is false on the
DDList, the page does not contain values to repopulate the DDList when it is
redispalyed.
-You can either enable-viewstate or repopulate the DDList yourself.
-If the post-back you are performing is the result of
add-this-new-record-to-the-DDList you will need to repopulate it anyway.
-You will also need to become familiar with the OnSelectedIndex_Change events.

(Please, don't take the names of the functions mentioned here literally. I'm
doing this off the top of my head.)
 
Hi Brad -

Thanks.

Here is what I am doing. Yes, I do all the steps you indicate. Then on a
if not ispostback I run a routine "Populate form" that runs a stored
procedure and selects a partcular record from the Database. Let's say
that the DDL was a list of students, then for this particular record I
have the student name in the record that was retrieved. I really don't
need to shoew the DDList again on the form as I don't want them changing
this value once entered anyway. But I cannot get the student name to
display at all. Typically a simple ddlname.selectedindex.text =
strstudentname
would have done it - but this time it will not work because the DDL was
created from a DB to begin with (my guess) - In the above scenario, how
can I populate that field on data retrieval? Thanks
 
Back
Top