从数据库中检索数据并将其存储在组合框中 [英] Retrieving data from database and storing in combobox

查看:101
本文介绍了从数据库中检索数据并将其存储在组合框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在aspx页面中有一个文本框和组合框,我的数据库有两列,分别是"Parent"和"Child",首先,当我在文本框中输入值时,组合框应该为空,它应该加载到数据库中,并且具有相同的值应该在aspx combobox中显示.随着我继续输入必须进入combobox的文本框值,此操作继续进行.当我从组合框中选择值并按提交时,它应显示在数据库的子级"列中.
谁能帮我一个忙.....................


I have a text box and combobox in aspx page, I have a database with two columns say "Parent" And "Child",First the combobox should be empty when I enter the value in textbox it should load to database ,and the same value sholud be displayed in aspx combobox.this has continue as i go on entering the textbox value it has to come to combobox. And when i select the value from combobox and press submit it should display on the database "Child" column.
Can any one help me please........................

推荐答案

尝试使用文本框控件的OnTextChange事件,用于通过将组合框的SelectedValue属性设置为数据库中的数据并填充组合框.
try using the OnTextChange event of the Textbox control to insert data in the database and populate the combobox by setting the SelectedValue property of the combobox.


首先,将文本框的自动回传正确性设置为true.
十个u在TextChanged事件中编写用于插入以及获取操作的代码


1st you set the autopostback properity of a textbox to true.
ten u write the code for insert as well as fetching operation in TextChanged event


protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
      //here when you leave the mouse cursor out of textbox this event is triggred 
        //now you can insert the data into database using the insert statement 
     //after inserting write the select query to fetch the data now here by doing this you will get the updated database value then you can bind it to drop down

 DropDownList1.DataSource=//here you will fetch the data from data base and put in some DataTabel or DataSet then 

DropDownList1.DataTextField="Parent";

DropDownList1.DataBind();




    }




希望对您有帮助




hope this will help you


这篇关于从数据库中检索数据并将其存储在组合框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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