﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - How to bind Webgrid to ISLinkDataSource with Stored Procedure</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-bind-Webgrid-to-ISLinkDataSource-with-Stored-Procedure/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to bind Webgrid to ISLinkDataSource with Stored Procedure</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-bind-Webgrid-to-ISLinkDataSource-with-Stored-Procedure/</link><pubDate>Sun, 03 Aug 2014 22:22:16 GMT</pubDate><dc:creator>yudi</dc:creator><description>&lt;p&gt;&lt;span style="color: #1f497d;"&gt;I modify Northwind.dbml file in WebGrid samples project by adding a stored procedure in the database. Right click the "Stored Procedure" folder in Server Explorer; create the SP; and save it.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Select ten most expensive products.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;ALTER procedure "Ten Most Expensive Products" AS
SET ROWCOUNT 10
SELECT Products.ProductName AS TenMostExpensiveProducts, Products.UnitPrice
FROM Products
ORDER BY Products.UnitPrice DESC&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;To consume the SP, drag and drop the stored procedure (from the Server Explorer) to the right pane of your dbml designer.&lt;br&gt;This will create following method in the designer file.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.[Ten Most Expensive Products]")]
public ISingleResult&amp;lt;Ten_Most_Expensive_ProductsResult&amp;gt; Ten_Most_Expensive_Products()
{
	IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
	return ((ISingleResult&amp;lt;Ten_Most_Expensive_ProductsResult&amp;gt;)(result.ReturnValue));
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;I'm using OnSelecting event of ISLinqDataSource to call the SP and populate the result.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;The aspx code.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;ISWebGrid:WebGrid ID="WebGrid1" runat="server" Height="300px" UseDefaultStyle="True"
    Width="400px" DataSourceID="ISLinqDataSource1" DefaultStyleMode="Elegant"
    OnPrepareDataBinding="WebGrid1_PrepareDataBinding"&amp;gt;
&amp;lt;/ISWebGrid:WebGrid&amp;gt;
&amp;lt;ISLinqDataSource:ISLinqDataSource ID="ISLinqDataSource1" runat="server"
    ContextTypeName="NorthwindDataContext" OnSelecting="ISLinqDataSource1_Selecting"&amp;gt;
&amp;lt;/ISLinqDataSource:ISLinqDataSource&amp;gt;&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;The aspx.cs (code behind) code.&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;protected void ISLinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
    NorthwindDataContext context = new NorthwindDataContext();
    e.Result = context.Ten_Most_Expensive_Products();
}

protected void WebGrid1_PrepareDataBinding(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
{
    if (!IsPostBack)
        WebGrid1.RetrieveStructure();
}&lt;/pre&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;When the page rendered in browser, the grid will look like following.&lt;/span&gt;&lt;/p&gt;
&lt;img src="http://www.intersoftpt.com/Community/Attachments/4091/ISLinqDataSourceStoredProcedure.jpg" style="height: 303px; width: 402px;"&gt;
&lt;p&gt;&lt;span style="color: #1f497d;"&gt;Hope this helps.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>How to bind Webgrid to ISLinkDataSource with Stored Procedure</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-bind-Webgrid-to-ISLinkDataSource-with-Stored-Procedure/</link><pubDate>Tue, 29 Jul 2014 18:19:14 GMT</pubDate><dc:creator>htalbert@eains.com</dc:creator><description>&lt;p&gt;Please advise how to bind a Webgrid to an ISLinqDataSource that uses a stored procedure in the DataContext.&lt;br&gt;&lt;/p&gt;</description></item></channel></rss>