This is a migrated thread and some comments may be shown as answers.

[Solved] Grid and stored procedure

2 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Emir
Top achievements
Rank 1
Emir asked on 19 Apr 2012, 07:18 AM

Hi,

I am trying to use a stored procedure to get all items from the database with EF 4.1 . I would like to apply pagination and filtering. Trying to give the grid IEnumrable but the SP is returning an ObjectResult<Entity>. If I try to convert it to IEnumrable then i get error:

The result of a query cannot be enumerated more than once.

Now is there any other way to do this without putting the pagination into the Stored Procedure or should I do custom binding? 

Thanks for your help.

2 Answers, 1 is accepted

Sort by
0
Peter
Top achievements
Rank 1
answered on 11 Jul 2012, 02:07 PM

Here's the controller, getting data using EF, passing the data to the view after using 'ToList()'.

 

var output = db.ExecuteStoreQuery<FormIQReport>("fiq_sp_formIQXMLReport @accountID={0}", AccountIDGet()).ToList();
return View(output);

The view works fine wih 'bound'

columns.Bound(e => e.Email).Width(100).Title("Email");

But not 'Template' which causes a 'browser cannot display the webpage' message.

<%= Html.Telerik().Grid(Model)
        .ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
        .Name("AlertReport")       
        .Columns(columns =>
                     {
                         columns.Template(e =>
                         {
                            %>
                            <a href="<%= e.Website %>">www.yahoo.com</a>
                            <%
                         }).Title("Website");

 


This is related to the original question, but having to do with 'columns.Template' not working.  Hopefully this will help flesh out the issues surrounding the problem.

 

 

0
Accepted
Peter
Top achievements
Rank 1
answered on 11 Jul 2012, 02:27 PM
Yes, using .ToList() did work, and the issue with 'columns.Template' was seperate. 

Was able get 'columns.Template' working by fiddling.  Here's what worked:
columns.Template(e =>
                                          "<a href=" + e.Website + " target='_blank' >" + e.Website + "</a>").Title("Website");

Tags
Grid
Asked by
Emir
Top achievements
Rank 1
Answers by
Peter
Top achievements
Rank 1
Share this question
or