Navigation

Search

Categories

On this page

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 112
This Year: 50
This Month: 0
This Week: 0
Comments: 0

Sign In

 Friday, April 18, 2008
Friday, April 18, 2008 12:30:59 PM (Eastern Standard Time, UTC-05:00) ( )


This is a simple example using LINQ to create a search form and display the results in a Gridview.

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Web.Configuration" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="System.Data.Linq" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">




<script runat="server"> Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Dim conString As String = WebConfigurationManager.ConnectionStrings("MyDatabase").ConnectionString Dim db As New DataContext(conString) Dim tMovie = db.GetTable(Of Movie)() grdMovies.DataSource = tMovie.Where(Function(m) m.Director.Contains(txtDirector.Text)) grdMovies.DataBind() End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>SearchMovies.aspx</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label id="lblDirector" Text="Director:" AssociatedControlID="txtDirector" Runat="server" /> <asp:TextBox id="txtDirector" Runat="server" /> <asp:Button id="btnSearch" Text="Search" OnClick="btnSearch_Click" Runat="Server" /> <br /><br /> <asp:GridView id="grdMovies" Runat="server" /> </div> </form> </body> </html>
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):