如何使用数据库从下拉列表中搜索数据 [英] how to search data from dropdownlist using database

查看:89
本文介绍了如何使用数据库从下拉列表中搜索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人告诉我如何使用下拉列表从数据库中搜索数据,例如用户选择名称(按名称)值从数据库中搜索记录,还有很多选项,例如按日期,按部门,按ID进行搜索.所有这些都在下拉列表中,请有人告诉您如何使用asp.net进行这种类型的搜索.c#

Pls some one tell that how to search data from database using dropdownlist, like user select name (by name)value to search record from the database, same many option are there like search datewise, department wise, id wise. And all are in dropdownlist, Pls someone tell that how to search data with this type of searching.using asp.net c#

推荐答案

有很多选择. .

就像您可以使用AjaxToolKit和AutoComplete Text Box中的级联下拉列表,后者使用Web Service呈现和搜索数据库中的数据....
There are many options for this...

Like you can use cascading drop downlist available from AjaxToolKit and AutoComplete Text Box which uses Web Service to render and search data from database...................


我认为您可以使用AutoCompleteExtender控件.

示例
I think you can use AutoCompleteExtender Control.

Example


在下拉列表中添加所有条件....
并在下拉列表中选择索引已更改事件获取所选项目并根据选择内容轻松写出您的条件...

像这样

add all the conditions in dropdownlist ....
and in dropdown selected index changed event get the selected item and write your condition based on the selection its easy......

like this

<asp:DropDownList ID="ddllist1" runat="server" OnSelectedIndexChanged="ddllist1_SelectedIndexChanged" >


<asp:ListItem>--select--</asp:ListItem>
<asp:ListItem>by name</asp:ListItem>
<asp:ListItem>department wise</asp:ListItem>
<asp:ListItem>by id</asp:ListItem>



在选定的索引中更改了这样写



in selected index changed write like this

if(ddllist1.selectedItem.Text=="by name")
{
//write corresponding condition
string query ="select * from table name where name="+your text;
}
else if(ddllist1.selectedItem.Text=="department wise")
{
//write corresponding condition to search by department
string query ="select * from table name where department="+your text;
}
else if(ddllist1.selectedItem.Text=="by id")
{
//write corresponding condition to search by id
string query ="select * from table name where id="+your text;
}


这篇关于如何使用数据库从下拉列表中搜索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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