954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Dropdown list Last value

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.

aish
Light Poster
26 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

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

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

Yes,it works thanks.

aish
Light Poster
26 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

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 tags, and then set the cboName's AppendDataBoundItems property to true. Though that's just a personal preference.

ChimpusDupus
Light Poster
47 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You