Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone,

I am making a website in which there are 15 static dropdownlist whose data are same, and the data are fetched from sql database. Now when i bind these dropdownlist with data in code behind i have to write a method which defines individual name of dropdownlist and then i bind it to data or else i need a method which will scan each and every controls on page and then it will select dropdownlist and then it will bind the data to it..but it is not a proper way , can any one please help me in doing it with javascript.. like i select data with query in code behind and then pass that data to javascript and it finds all the dropdownlist with its Type method and bind the data with it..

Please help me out ...i am really stuck up..

Regards,
Krunal panchal
Posted
Comments
armagedescu 16-Jul-12 10:29am    
I don't see how this is related to C++

1 solution

Hi,

So you have 15 dropdown's and all DataSource are same right...

Fetch Data One and Store it in a DataTable and Then Bind all Dropdown's with same DataTable.

In this way you can reduce fetching time of your application.

you can loop each control and Check their type and Bind DataSource if required.

C#
foreach (Control c in Page.Controls)
        {
            foreach (Control childc in c.Controls)
            {
                if (childc is ComboBox)
                {
                    childc.DataSource=[Your DataSource]
                    childc.DataBind();
                }
            }
        }



Other way

you can do it in javascript but in each term you have to fetch data once from your DB
if you dont have any caching mechanization. So why we will go for java script we will do in our code behind.
 
Share this answer
 
v2

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