0
votes

I am working on an asp.net page and trying to improve its load time. It takes about 8 seconds to load 20 records in a listview.

The page was loading properly in spite of being slow using eval as follows:

<asp:LinkButton CommandArgument='<%#Eval("EmployeeID")%>' >Edit</asp:LinkButton>

However, because the previous approach was slow, I changed it to the following based on info I read here:

<asp:LinkButton CommandArgument='<%# ((DataRowView)Container.DataItem)["ApplicationID"]%>'>Edit</asp:LinkButton>

However the new code produces the following error: Unable to cast object of type DataObjects.Data.EmployeeInfo to type 'System.Data.DataRowView

Now, I am not that familiar with the second method but the load time of the first method is unacceptable. things to Note:

  • There is a class called EmployeeInfo
  • Data is being retrieved from sqlServer via a stored procedure
  • The stored procedure gets data from a view
  • There is a listview whose datasource is set the the results of a method that returns a List of EmployeeInfo: List
  • listview.databind() is called after the datasource is set
  • There are 10 field in each record that all give the same error when I change from eval to the aforementioned approach
  • The program crashes after databind() is called indicating the casting problem

the sample code I saw used DataRowView and DataItem. Am I supposed to change DataRowView or DataItem to something else? What do I need to do to correct this error?

1

1 Answers

1
votes

Change <asp:LinkButton CommandArgument='<%# ((DataRowView)Container.DataItem)["ApplicationID"]%>'>Edit</asp:LinkButton>

to

<asp:LinkButton CommandArgument='<%# ((DataObjects.Data.EmployeeInfo)Container.DataItem).ApplicationID %>'>Edit</asp:LinkButton>

This is unlikely to make any significant improvement to your load time though. 8 seconds to load 20 records is almost certainly unrelated to Eval or casting. It would likely indicate a performance issue in your stored procedure/database code. You should run SQL Server Profiler to get an accurate sense of how long your database query is taking. If it is confirmed that the issue is with your stored procedure/view, then you can use SSMS Query Analyzer to identify bottlenecks and what you could do to improve performance. If you want to post your Query Analyzer results, we can further help you from there.