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.

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

Yes,it works thanks.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.