I have a gridview as follows:
<asp:GridView ID="gv" runat="server" SelectMethod="gv_GetData" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="true">
</asp:GridView>
I have the following code in c# that works:
public IList<string> gv_GetData(int maximumRows, int startRowIndex, out int totalRowCount, string sortByExpression)
{
List<string> l = GetTestData();
totalRowCount = l.Count;
return l;
}
private List<string> GetTestData()
{
List<string> l = new List<string>();
l.Add("a");
l.Add("b");
l.Add("c");
return l;
}
Now, in VB I have:
Public Function gv_GetData(maximumRows As Integer, startRowIndex As Integer, ByRef totalRowCount As Integer, sortByExpression As String) As IList(Of String)
Dim l As List(Of String) = GetTestData()
totalRowCount = l.Count
Return l
End Function
Private Function GetTestData() As List(Of String)
Dim l As New List(Of String)()
l.Add("a")
l.Add("b")
l.Add("c")
Return l
End Function
The VB version always generates the following error:
When the DataBoundControl has paging enabled, either the SelectMethod should return an IQueryable or should have all these mandatory parameters : int startRowIndex, int maximumRows, out int totalRowCount
Could this be a framework bug? Or am I missing something overly obvious?
Answered by nemesv below. New method is:
Public Function gv_GetData(maximumRows As Integer, startRowIndex As Integer, <System.Runtime.InteropServices.Out()> ByRef totalRowCount As Integer, sortByExpression As String) As IList(Of String)
Dim l As List(Of String) = GetTestData()
totalRowCount = l.Count
Return l
End Function
You need to mark the totalRowCount
with the OutAttribute
<Out()> ByRef totalRowCount As Integer
This is semantically equivalent with the c# out
keyword.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With