Sanjay Kumar

Sanjay Kumar

  • NA
  • 5k
  • 4.4m

How to filter Gridview data using Linq Query

Oct 19 2013 2:44 AM
 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();
}

Answers (5)