gridview搜索问题 [英] gridview searching problem

查看:61
本文介绍了gridview搜索问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中有一个gridview,并且有一个数据源
假设Gridview ID为Gridview1
Sqldatasourse是SqlDataSource1
我有一个像下面的表格

I have a gridview in my project and i have a datasource
Let us say Gridview ID is Gridview1
Sqldatasourse is SqlDataSource1
I have a Table Like below

Table Name:StudentInfo

UserId	UserName	FirstName	LastName	City		Designation
1	krishna		krishna		reddy		Hyderabad	Developer
2	Mohan		Mohan Prasad	Kumar		Hyderabad	Developer
3	Naresh		Naresh Kumar	Naresh Babu	Hyderabad	Designer



我在SqlDatasource1中有一个查询,其名称为SELECT *FROM StudentInfo

我有一个DropdownListUserName
在DropDownList中,用户名是Krishna,mohan,Naresh

当我选择奎师那时,它必须显示奎师那行
当我选择mohan时,必须显示mohan行
这样的

对于我在ConfigDatasource中使用Where子句的问题,但加载页面时出现的问题是它自动过滤表,我不知道
想要这样,当我手动选择用户名时,只有它可以工作



I have a query in SqlDatasource1 as SELECT *FROM StudentInfo

I have a DropdownListUserName
in DropDownList UserNames are Krishna,mohan,Naresh

when i select krishna it has to show krishna row
when i select mohan it has to show mohan row
like that

For the i used Where clause in ConfigDatasource but the problem when the page is loaded it filters the table automatically i dont
want like that when i select the username manually then only it has to work
how to do that

推荐答案

如果将GridView附加到DataView并将sqldatasource附加到DataView,则可以使用Filter选项(搜索类型)
If you attach the GridView to a DataView and attach your sqldatasource to the DataView you can use Filter options (kind of search)


您好,Prera​​k我正在告诉您步骤.
1.使用一种方法说SearchStudent(ddlStudent.SelectedItem.ToString())
您可以像这样使用它-
gvStudentInfo.DataSource = SearchStudent(ddlStudent.SelectedItem.ToString());

然后您可以在内部方法中编写

公共静态列表< studentinfo> SearchStudent(字符串名称)
{
列表< studentinfo> studentInfo;
var searchExpression = PredicateBuilder.Make< studentinfo>(u => u.UserId> 0);
如果(!string.IsNullOrEmpty(SearchValue.Trim()))
{
开关(名称)
大小写名称":
searchExpression = searchExpression.And(n => n.UserName.StartsWith(SearchValue.Trim()));
休息;
}
返回studentInfo.OrderByDescending(u => u.UserID).ToList();
}
您也可以使用上述方法..如果您想更简单,请通知我.我会以最简单的方式去.
Hello Prerak i am telling you the steps.
1.use one method say SearchStudent(ddlStudent.SelectedItem.ToString())
You can use this one like that-
gvStudentInfo.DataSource=SearchStudent(ddlStudent.SelectedItem.ToString());

then inside methods u can write

public static List<studentinfo> SearchStudent(string name)
{
List<studentinfo>studentInfo;
var searchExpression = PredicateBuilder.Make<studentinfo>(u=> u.UserId> 0);
if (!string.IsNullOrEmpty(SearchValue.Trim()))
{
switch (name)
case "name":
searchExpression = searchExpression.And(n=>n.UserName.StartsWith(SearchValue.Trim()) );
break;
}
return studentInfo.OrderByDescending(u=>u.UserID).ToList();
}
you can go for above method also.. if you want more simple then inform me. i will go for simplest way.


这篇关于gridview搜索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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