Thursday, September 9, 2010

Example on using the Linq to query the array of citys and bind the result to the grid

by Narendra, .Net Developer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Text;

namespace examples_Post
public partial class exp10 : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
// Creating the array of Cities
string[] Citys = { "Belfast", "Hamburg", "Austria", "Paris",
"Cardiff", "Copenhegan", "Warsa",
"Belgium", "Berlin", "Dublin" };
// Using the LINQ Query expression against the array and assign the result to the GridView(GV_Citys) for binding
GV_Citys.DataSource = from city in Citys
where city.Length > 6 // Selecting the city names greater than 5 characters from array of citys
orderby city
select city.ToUpper(); // Covert the citys list into Uppercase

GV_Citys .DataBind();


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="exp10.aspx.cs" Inherits="examples_Post.exp10" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
<form id="form1" runat="server">
<asp:Label ID="lblexmsg" runat="server" Font-Size="Large" Font-Bold="true" ForeColor="OrangeRed" Text="Example on using the Linq to query the array of citys and bind the result to the gridview "></asp:Label>
<h3 >City Names</h3>
<asp:GridView ID="GV_Citys" Font-Bold="true" ForeColor="Blue" AlternatingRowStyle-ForeColor="Brown" runat="server">


No comments:

Post a Comment