Я использую метод SelectMethod ретранслятора asp.net для возврата моих объектов. Можно ли получить количество возвращаемых предметов?Repeater SelectMethod - Как получить количество возвращенных элементов?
Я изначально использовал <%#: Items.Count %>
, но быстро понял, что не возвращает правильное количество возвращаемых объектов.
<asp:Repeater ID="docResults" runat="server"
ItemType="ArchiveViewer.Models.Document"
SelectMethod="GetSearchResults" >
<HeaderTemplate>
<p class="result-info">
Found <strong> <%#: Items.Count %> </strong> results.
</p>
</HeaderTemplate>
<ItemTemplate>
<div>
Title: <%#:Item.Metadata.Title %>
</div>
<div>
Author: <%#:Item.Metadata.Author %>
</div>
</ItemTemplate>
</asp:Repeater>
EDIT: В соответствии с просьбой: мой метод GetSearchResults ...
[WebMethod]
public IEnumerable<Document> GetSearchResults(
[QueryString("query")] string query,
[QueryString("type")] string queryType)
{
IEnumerable<Document> results = null;
try
{
ArchiveSearcher searcher = new ArchiveSearcher();
results = searcher.SearchMetadata(query, queryType, 1, 20);
if (results.Count() > 0)
{
// Display the first search result in the viewer
Document firstResult = results.FirstOrDefault();
hfCurrentDocId.Value = firstResult.DocumentId.ToString();
hfImageDir.Value = firstResult.FolderPath;
hfObjectData.Value = firstResult.JSONPath;
}
}
catch (Exception ex)
{
// Log the exception.
ArchiveViewer.Logic.ExceptionUtility.LogException(ex,
"GetSearchResults in Search.aspx.cs");
}
return results;
}
Спасибо!
Что вы получаете за '<% #: Items.Count%>'? –
«Элементы» - это список менеджеров сценариев. Я не знаю, почему ... – Tums
Покажите нам 'GetSearchResults' –