使用javascript动态绑定下拉列表 [英] Binding dropdownlist dynamically with javascript

查看:93
本文介绍了使用javascript动态绑定下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在创建一个网站,其中有15个静态下拉列表,其数据相同,并且数据是从sql数据库中获取的。现在,当我将这些下拉列表与代码后面的数据绑定时,我必须编写一个方法来定义下拉列表的个别名称然后我将其绑定到数据,否则我需要一个方法来扫描页面上的每个控件然后它将选择dropdownlist然后它会将数据绑定到它..但它不是一个正确的方法,任何人都可以帮助我用javascript做它...就像我选择数据与代码隐藏后,然后将数据传递给javascript和它找到所有带有Type方法的下拉列表并用它绑定数据..



请帮帮我...我真的被困了..



问候,

Krunal panchal

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

推荐答案





所以你有15个下拉列表并且所有DataSource都是相同的...



获取数据并将其存储在DataTable中然后使用相同的DataTable绑定所有Dropdown。



通过这种方式你可以减少fetchi申请时间。



您可以循环每个控件并检查其类型和Bind DataSource(如果需要)。



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.

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







其他方式



你可以在javascript中完成它但在每个术语中你必须从你的数据库中获取一次数据

如果你没有任何缓存机制。那么为什么我们要使用java脚本,我们将在后面的代码中执行。




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.


这篇关于使用javascript动态绑定下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆