如何将数据绑定到文本框和下拉列表中 [英] how to bind data into textbox and dropdownlist
本文介绍了如何将数据绑定到文本框和下拉列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将数据绑定到文本框和下拉列表。
首先,我从文本框和下拉列表中插入数据。
我想在下拉列表中显示数据,因为我在插入数据时我检索数据到文本框。
解决方案
从你的问题我只知道你想在TextBox中写入数据后立即将数据绑定到下拉列表....纠正我如果我错了。
基于我所理解的写作解决方案。
文本框中有onblur事件
onblur你可以编写javascript函数在你的下拉列表中添加新列表
函数 AddTextboxValueToDDL(sender)
{
var text = document .getElementById(' <%= TxtData.ClientID%>')。value;
var opt = document .createElement( 选项);
// 将选项对象添加到下拉/列表框
document .getElementById( ddllist)。 。新增(优化);
// 为Option对象分配文本和值
opt.text = text ;
opt.value = text;
}
// 在您的页面中有文本框和下拉列表
< asp:textbox id = TxtData onblur = AddTextboxValueToDDL(this); runat = server xmlns:asp = #unknown 跨度>>
< asp:dropdownlist id = ddllist runat = server appenddatabounditems = true />
< / asp:textbox > 跨度>
how to bind data into textbox and dropdownlist.
Firstly, I insert data from textbox and dropdownlist.
I want to show data in dropdownlist as i inserted data when i retrieve data to textbox.
解决方案
from your question i only understood is you want to bind data to dropdownlist as soon as wrote data in TextBox.... correct me if i am wrong.
so based on what i understood m writing solution.
there is "onblur" event for textbox
onblur you can write javascript function to add new list in your dropdown list
function AddTextboxValueToDDL(sender) { var text=document.getElementById('<%= TxtData.ClientID %>').value; var opt = document.createElement("option"); // Add an Option object to Drop Down/List Box document.getElementById("ddllist").options.add(opt); // Assign text and value to Option object opt.text = text; opt.value = text; } //and in your page there is textbox and dropdown list <asp:textbox id="TxtData" onblur="AddTextboxValueToDDL(this);" runat="server" xmlns:asp="#unknown"> <asp:dropdownlist id="ddllist" runat="server" appenddatabounditems="true" /> </asp:textbox>
这篇关于如何将数据绑定到文本框和下拉列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文