5

我有一个gridview如下:

<asp:GridView ID="gv" runat="server" SelectMethod="gv_GetData" AllowPaging="true" AllowSorting="true" AutoGenerateColumns="true">
</asp:GridView>

我在 c# 中有以下代码有效:

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;
}

现在,在VB中我有:

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

VB版总是产生如下错误:

当 DataBoundControl 启用分页时,SelectMethod 应该返回一个 IQueryable 或者应该具有所有这些强制参数:int startRowIndex、int maximumRows、out int totalRowCount

这可能是一个框架错误吗?还是我错过了一些过于明显的东西?


由下面的 nemesv 回答。新方法是:

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
4

1 回答 1

8

您需要totalRowCountOutAttribute标记

<Out()> ByRef totalRowCount As Integer

这在语义上与 c#out关键字等效。

于 2012-08-21T17:08:40.440 回答