How to filter Gridview data using Linq Query

Posted by Webmasters964 under C# on 10/19/2013 | Points: 10 | Views : 3367 | Status : [Member] | Replies : 2
Select :<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true">
<asp:ListItem Text="---Select---"></asp:ListItem>
<asp:ListItem Text="StudentName"></asp:ListItem>
<asp:ListItem Text="Email"></asp:ListItem>
<asp:ListItem Text="Mobile"></asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
<div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
</div>

private void BindGrid()
{
var query = from p in db.StudentTables select new { p.StudentID, p.StudentName,p.Mobile,p.Email };
GridView1.DataSource = query;
GridView1.DataBind();
}




Responses

Posted by: Bandi on: 10/20/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
add WHERE condition in the select query
var query = from p in db.StudentTables
where condition

select new { p.StudentID, p.StudentName,p.Mobile,p.Email };

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Webmasters964, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Samirbhogayta on: 10/21/2013 [Member] Starter | Points: 25

Up
0
Down
Hi..I request to follow this link for your solution.

http://stackoverflow.com/questions/792805/filter-gridview-results-using-linq-to-sql-object-datasource-with-a-like-operator

SAMIR
Sr. Software Engineer

Webmasters964, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response