Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
here, I want to add values into dropdownlist programatically(here i want to get values from database table) in c# with Asp.net.I want to make acommon function to use for no of dropdownlist control.so, please help me to solve this problem.
In my project,I want to add state names into dropdownlist.Please help me..SEnd me code for this function.
Posted
Updated 4-Jun-11 21:12pm
v2
Comments
Wonde Tadesse 4-Jun-11 22:42pm    
Have you tried something ?
Sergey Alexandrovich Kryukov 5-Jun-11 21:14pm    
Add the tag: ASP.NET.
--SA

1 solution

Try
C#
public void AddDropDownList(DropDownList obj,string[] arr)
   {
       for (int i = 0; i < arr.Length; i++)
       {
           obj.Items.Add(arr[i]);
       }
   }

you can use function this function to store values in given ways
C#
string[] arr = { Names of States };
      AddDropDownList(DropDownList1, arr); // Storing Names of State to DropDownList1 Control
 
Share this answer
 
Comments
TweakBird 5-Jun-11 3:05am    
Good answer. my 5!
RaviRanjanKr 6-Jun-11 7:16am    
Thanks :)
Kim Togo 5-Jun-11 7:59am    
Good one. My 5.
RaviRanjanKr 6-Jun-11 7:16am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900