DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   Dropdown list Last value (http://www.daniweb.com/forums/thread31820.html)

aish Sep 6th, 2005 5:54 am
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.

Paladine Sep 6th, 2005 12:59 pm
Re: Dropdown list Last value
 
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

aish Sep 7th, 2005 2:43 am
Re: Dropdown list Last value
 
Yes,it works thanks.

ChimpusDupus Jul 7th, 2006 4:46 pm
Re: Dropdown list Last value
 
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.


All times are GMT -4. The time now is 9:48 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC