Click here to Skip to main content
16,017,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


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
Posted
Updated 12-Sep-11 22:36pm
v2
Comments
Prerak Patel 13-Sep-11 4:36am    
Added pre tags

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.
 
Share this answer
 
If you attach the GridView to a DataView and attach your sqldatasource to the DataView you can use Filter options (kind of search)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900