用于将数据绑定到下拉列表的javascript函数 [英] javascript function for binding data to drop down list

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

问题描述

如何使用javascript将fron数据库的值绑定到下拉列表?


我在这里解释我的问题

我使用

How to bind values fron database to dropdown list using javascript?


i explain my problem here

i use

<select name="lstDropDown_A" id="lstDropDown_A" onkeydown="fnKeyDownHandler(this, event);"
onkeyup="fnKeyUpHandler_A(this, event); return false;" onkeypress="return fnKeyPressHandler_A(this, event);"
onchange="fnChangeHandler_A(this, event);"  runat="server" style="width: 155px"  önclick="return lstDropDown_A_onclick()">
<option>Enter Commodity name</option></select>



此下拉列表的第一项是可编辑的(通过javascript完成)

我也将数据绑定到具有数据集的此下拉列表.

现在我想根据上面的下拉列表项的选择将数据绑定到其他下拉列表

但是由于这是HTML控件的textchanged事件不适用,因此onclick ="return lstDropDown_A_onclick()"函数我想进行数据绑定



the first item of this drop list is editable (do it through javascript)

Also i bind the data to this drop down list with dataset.

Now i want to bind data to unother dropdown list depending upon the selection of above droplist item

But as this is HTML control textchanged event is not applicable so onclick="return lstDropDown_A_onclick()" function i want to do data binding

推荐答案

使用JavaScript从数据库绑定.数据必须以相同的方式发送到客户端,但是由于您使用的是ASP.NET,因此仅使用ASP.NET数据绑定会更加简单和容易.

[edit]澄清您的问题后[/edit]

试试这样的

You can''t really bind from a database using JavaScript. The data must be sent to the client in same manner but since you are using ASP.NET it would be far simplier and easier to just use ASP.NET databinding.

[edit]After clarification of your question[/edit]

Try something like this

<select id="SelectA"  önchange="UpdateB()">
 <option value="1" text="One"/>
 <option value="1" text="Two"/>
</select>

<select ID="SelectB"></select>

function UpdateB()
{


.ajax({ 输入:"POST", 网址:"myPage.aspx/GetB", 数据:
.ajax({ type: "POST", url: "myPage.aspx/GetB", data:


(#SelectA").val(), contentType:"application/json", dataType:"json", 成功:OnSuccess }); } 函数OnSuccess(数据) { //遍历数据并添加选项元素
("#SelectA").val(), contentType: "application/json", dataType: "json", success: OnSuccess }); } function OnSuccess(data) { // Iterate through data and add option elements


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

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