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?