Like linq query example and bind gridview

50 %
50 %
Information about Like linq query example and bind gridview
Technology

Published on April 24, 2014

Author: VijaySaklani

Source: slideshare.net

Description

Like linq query example and bind gridview.

Introduction: In this article today I will explain Like linq query example and bind gridview. Description: In the previous article I have explained Server side validation in MVC Razor using data annotation, URL routing in asp.net website, Populate Dropdown List dynamically using Asp.net MVC Razor, Code First migration in asp.net MVC 4, Populate Cascading Dropdown List in Asp.net MVC4 using Json and Jquery and What is Asp.net MVC? Its advantages and disadvantges. I have a table Product: ID int PRODUCT_NAME varchar(50) DESCRIPTION varchar(50) PRODUCT_PRICE int I want to search products on product name and display the matched results in gridview. Add a new webform to project and design the .aspx page as shown: <fieldset style="width:420px"> <legend>Like with Linq query Example</legend> <table width="100%"> <tr><td>Enter Product Name:</td><td><asp:TextBox ID="txtsearch" runat="server"></asp:TextBox></td></tr> <tr><td></td><td><asp:Button ID="btnserach" runat="server" onclick="btnserach_Click"T ext="Button" /></td></tr> <tr><td></td>

<table> <tr> <asp:GridView ID="GridView1" runat="server" EmptyDataText="No records Found" ShowHeaderWhenEmpty="True" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="408px"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:BoundField DataField="PRODUCT_NAME" HeaderText="Product Name" /> <asp:BoundField DataField="DESCRIPTION" HeaderText="Description" /> <asp:BoundField DataField="PRODUCT_PRICE" HeaderText="Price" /> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView></tr> </table></tr> </table> </fieldset> On button click write the given code on .aspx.cs page: DataClasses1DataContext db = new DataClasses1DataContext(); protected void btnserach_Click(object sender, EventArgs e) { var product = from p in db.PRODUCTs where p.PRODUCT_NAME.Contains(txtsearch.Text.Trim()) select p; GridView1.DataSource = product; GridView1.DataBind();

} OR using System.Data.Linq.SqlClient; protected void btnserach_Click(object sender, EventArgs e) { var product = from p in db.PRODUCTs where SqlMethods.Like(p.PRODUCT_NAME, "%" + txtsearch.Text + "%") select p; GridView1.DataSource = product; GridView1.DataBind(); } Build the project and run. Is this article helpful for you? If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

Add a comment

Related presentations

Presentación que realice en el Evento Nacional de Gobierno Abierto, realizado los ...

In this presentation we will describe our experience developing with a highly dyna...

Presentation to the LITA Forum 7th November 2014 Albuquerque, NM

Un recorrido por los cambios que nos generará el wearabletech en el futuro

Um paralelo entre as novidades & mercado em Wearable Computing e Tecnologias Assis...

Microsoft finally joins the smartwatch and fitness tracker game by introducing the...

Related pages

c# - gridview row bind to linq query - Stack Overflow

... of a gridview. I'm trying to create a table like the ... bind a LINQ query to the row of a gridview. ... to bind the queries to the gridview rows.
Read more

Simple GridView Binding using LINQ to SQL - CodeProject

Soon we will use this table to bind GridView to ... simple GridView binding using LINQ to ... the query results, see example ...
Read more

Binding Gridview using LINQ - C# Corner - Developers and ...

This article shows how to Bind Gridview using Linq. 50.8 k; 0; 0; facebook; twitter; ... The code behind to fetch the records through linq and bind it to ...
Read more

C# Using Linq to Query DataTable and Bind to Gridview

C# Using Linq to Query DataTable and Bind to Gridview. ... I am little bit late..but would like to share my example with you, DataTable dt = new DataTable();
Read more

LINQ IQUeryable Binding To GridView

LINQ IQUeryable Binding To GridView. ... a LINQ query, and binding it to a gridview control ... paging when I am trying to bind IList object to gridview.
Read more

How to bind return result set of LInq Query to Gridview

Hi all, i want to bind the LINQ query result to a gridview i have created a class where i ... datasource like, ... set as datasource. example is ...
Read more

.net - LINQ query against GridView filled with ...

I need to make a LINQ query against GridView filled with SqlDataSource ... LINQ query against GridView filled ... Bind a list returned from a LINQ query ...
Read more

gridviewrow bind to linq query | The ASP.NET Forums

... I need to bind a LINQ query to the row of a gridview. ... to the row of a gridview. I'm trying to create a table like the matrix in ... Samples; Forums ...
Read more

LINQ TO SQL GridView (Enhanced Gridview) - CodeProject

LINQ TO SQL GridView ... Create and store orderby expression which in turn is used by the linq query info class collection. ... Bind gridview with ...
Read more