Help with dropdownlist data adding?

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 1
Reputation: Lemon is an unknown quantity at this point 
Solved Threads: 0
Lemon Lemon is offline Offline
Newbie Poster

Help with dropdownlist data adding?

 
0
  #1
Jul 1st, 2005
Well, I'm hoping someone can help me....

I've got a web application that queries data from a database based on selections made in previous dropdownlists. The problem is that some of the final queries return only one data item.

I'm using the onSelectedIndexChanged with autopostback enabled as my events in the lists. And thats the problem, if theres only one item in the dropdownlist, its imposible to change the index, thus I've got no event firing the next block of code I need executed...

If anyone has any idea on how to counter this problem, please help!
I thought if it were possible to add data to already manually inputted items already in the list, that'd be great, so that there's already 1 item in there before the other items are added... So that if only one item is retrieved by the from the database, there will be at least two items in there, allowing a change in the selected index...

Just how to do that though, I have no idea!
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 13
Reputation: earlofroberts is an unknown quantity at this point 
Solved Threads: 1
earlofroberts earlofroberts is offline Offline
Newbie Poster

Re: Help with dropdownlist data adding?

 
0
  #2
Jul 5th, 2005
Lemon,
I load my ddlboxes with a datareader. The first item has a value of 0 and I set the text to 'Select an item below' or something like that. I sometimes leave it blank. In any event, if they make a selection, the SelectedIndexChanged event fires.

Hope this helps,
earlofroberts
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 41
Reputation: npasma is an unknown quantity at this point 
Solved Threads: 0
npasma's Avatar
npasma npasma is offline Offline
Light Poster

Re: Help with dropdownlist data adding?

 
0
  #3
Jul 6th, 2005
Yep, having a default value for drop down lists is a good habit to get into I think. Try code something like this:

  1. Dim rdrCategory As SqlDataReader
  2. myConnection.Open()
  3. rdrCategory = cmdSelect.ExecuteReader(CommandBehavior.CloseConnection)
  4. Dim liDefault As ListItem
  5. liCategory = New ListItem([insert text for default entry here as String], [insert default value here as String])
  6. lstCategories.Items.Add(liDefault)
  7. Do While rdrCategory.Read()
  8. liCategory = New ListItem(rdrCategory("ShortName"), _
  9. rdrCategory("CategoryID")
  10. lstCategories.Items.Add(liCategory)
  11. Loop
  12. rdrCategory.Close()
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 9
Reputation: vrushalinz1 is an unknown quantity at this point 
Solved Threads: 0
vrushalinz1 vrushalinz1 is offline Offline
Newbie Poster

Re: Help with dropdownlist data adding?

 
0
  #4
Jul 8th, 2005
Originally Posted by Lemon
Well, I'm hoping someone can help me....

I've got a web application that queries data from a database based on selections made in previous dropdownlists. The problem is that some of the final queries return only one data item.

I'm using the onSelectedIndexChanged with autopostback enabled as my events in the lists. And thats the problem, if theres only one item in the dropdownlist, its imposible to change the index, thus I've got no event firing the next block of code I need executed...

If anyone has any idea on how to counter this problem, please help!
I thought if it were possible to add data to already manually inputted items already in the list, that'd be great, so that there's already 1 item in there before the other items are added... So that if only one item is retrieved by the from the database, there will be at least two items in there, allowing a change in the selected index...

Just how to do that though, I have no idea!

hi

u can make a check for only one item in the dropdownlist ,if its true make a call to the onSelectedIndexChanged with the required parameter


hope this helps u out
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC