Dropdown list Last value

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2005
Posts: 26
Reputation: aish is an unknown quantity at this point 
Solved Threads: 0
aish's Avatar
aish aish is offline Offline
Light Poster

Dropdown list Last value

 
0
  #1
Sep 6th, 2005
I fill dropdown lists values from the database then I wants to hard code first value and last value. I already hard code first value it's like this.

cboName.Items.Insert(0,new ListItem("----Select----","0"));

how can I hard code last value of the dropdown list, I want to add last value as a ----Other----. can anyone help me?
Thanks.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: Dropdown list Last value

 
0
  #2
Sep 6th, 2005
Do a count of the number of ListItems, and then store that in a variable and add 1 and then add your last value = Other

example:
nCount = {count of the number of item entries in the dropdownlist}

cboName.Items.Insert(nCount + 1,new ListItem("OTHER","0"));

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

Re: Dropdown list Last value

 
0
  #3
Sep 7th, 2005
Yes,it works thanks.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 47
Reputation: ChimpusDupus is an unknown quantity at this point 
Solved Threads: 0
ChimpusDupus ChimpusDupus is offline Offline
Light Poster

Re: Dropdown list Last value

 
0
  #4
Jul 7th, 2006
I believe you can also do the following:

cboName.Items.Add(new listitem("Other","0"))

'item_name' would be the name of the item you want to add

And, another option for hard-coding the first entry, or the first several entries is to add the entries on the actual .aspx page in the <asp:listitem> tags, and then set the cboName's AppendDataBoundItems property to true. Though that's just a personal preference.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC