我正在努力实现与此poster相同的功能,并且我正在关注我需要做的answers之一。
这是我的方法
public void DisplayItemRangeForCurrentPage()
{
var totalRecords = ((DataView)gvMagicalSearchResults.DataSource).Count;
var endRecord = gvMagicalSearchResults.PageSize * (gvMagicalSearchResults.PageIndex + 1);
var startsRecods = endRecord - gvMagicalSearchResults.PageSize;
if (endRecord > totalRecords)
endRecord = totalRecords;
if (startsRecods == 0) startsRecods = 1;
if (endRecord == 0) endRecord = totalRecords;
var str = new StringBuilder();
str.Append((string)HttpContext.GetGlobalResourceObject("magicalResx", "GrivSearchCountMessage_Shows"));
str.Append(" " + startsRecods + " - " + endRecord + " ");
str.Append((string)HttpContext.GetGlobalResourceObject("magicalResx", "GrivSearchCountMessage_OfTotal"));
str.Append(" " + totalRecords + " ");
ltrResultsCount.Text = str.ToString();
}
无论我在何处调用此方法,它都会在var totalRecords = ((DataView)gvMagicalSearchResults.DataSource).Count;
行上抛出“未设置为对象实例的对象”错误。
我尝试在几个GridView / ObjectDataSource事件中调用它。我尝试在PreRender
,OnLoad
,Render
中调用它 - 唉,它们都没有用...
那么有人能告诉我在事件周期中gridview获取其数据源的位置吗?
答案 0 :(得分:0)