iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
Please advise how to bind a Webgrid to an ISLinqDataSource that uses a stored procedure in the DataContext.
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.
Select ten most expensive products.
ALTER procedure "Ten Most Expensive Products" AS SET ROWCOUNT 10 SELECT Products.ProductName AS TenMostExpensiveProducts, Products.UnitPrice FROM Products ORDER BY Products.UnitPrice DESC
To consume the SP, drag and drop the stored procedure (from the Server Explorer) to the right pane of your dbml designer.This will create following method in the designer file.
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.[Ten Most Expensive Products]")] public ISingleResult<Ten_Most_Expensive_ProductsResult> Ten_Most_Expensive_Products() { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()))); return ((ISingleResult<Ten_Most_Expensive_ProductsResult>)(result.ReturnValue)); }
I'm using OnSelecting event of ISLinqDataSource to call the SP and populate the result.
The aspx code.
<ISWebGrid:WebGrid ID="WebGrid1" runat="server" Height="300px" UseDefaultStyle="True" Width="400px" DataSourceID="ISLinqDataSource1" DefaultStyleMode="Elegant" OnPrepareDataBinding="WebGrid1_PrepareDataBinding"> </ISWebGrid:WebGrid> <ISLinqDataSource:ISLinqDataSource ID="ISLinqDataSource1" runat="server" ContextTypeName="NorthwindDataContext" OnSelecting="ISLinqDataSource1_Selecting"> </ISLinqDataSource:ISLinqDataSource>
The aspx.cs (code behind) code.
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(); }
When the page rendered in browser, the grid will look like following.
Hope this helps.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname