So, I'm trying to display something like "Displaying 1-20 of 100" using a RadGrid control. I put the following code in the RadGrid1_PageIndexChanged event:
int showingRowsFrom = ((e.NewPageIndex + 1) * rgResults.PageSize) - rgResults.PageSize + 1;
int showingRowsTo;
if ((e.NewPageIndex + 1) == rgResults.PageCount)
{
showingRowsTo = GridSource.Tables[0].Rows.Count;
}
else
{
showingRowsTo = (e.NewPageIndex + 1) * rgResults.PageSize;
}
string rowCount = string.Format("Displaying {0}-{1} of {2}", showingRowsFrom, showingRowsTo, GridSource.Tables[0].Rows.Count);
lblResultsCountBottom.Text = lblResultsCountTop.Text = rowCount;
Unfortunately, it looks like this doesn't do a full postback and the label doesn't end up getting updated. How can I go about doing this? I tried doing it client side and had problems with this, too. It says $find is undefined.
$(document).ready(function () {
var grid = $find("<%=rgResults.ClientID%>");
var mtv = grid.get_masterTableView();
var pageIndex = mtv.get_currentPageIndex();
alert(pageIndex);
});
Here's the radgrid code:
<radG:RadGrid ID="rgResults" runat="server" AllowMultiRowSelection="True" AllowPaging="True"
AllowSorting="True" EnableAJAX="False" GridLines="None" OnItemCommand="rgResults_ItemCommand" OnItemDataBound="rgResults_ItemDataBound"
PageSize="20"
Skin="Default" Width="100%" OnPageIndexChanged="rgResults_PageIndexChanged" OnSortCommand="rgResults_SortCommand" OnInit="rgResults_Init" OnPreRender="rgResults_PreRender">
<ClientSettings ApplyStylesOnClient="True">
</ClientSettings>
<ItemStyle CssClass="griditemtext" />
<HeaderStyle CssClass="gridheadertext" />
<FooterStyle CssClass="gridfootertext" />
<AlternatingItemStyle CssClass="gridalternetitemtext" />
<PagerStyle CssClass="gridpagertext" Mode="NumericPages" />
<CommandItemStyle CssClass="gridcommandtext" />
<SelectedItemStyle CssClass="gridselecteditemtext" />
<MasterTableView AutoGenerateColumns="False"
DataKeyNames="Article Number" Font-Bold="False" Font-Italic="False" CommandItemDisplay="None" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" GridLines="Both">
<ExpandCollapseColumn Visible="False">
<HeaderStyle Width="19px" />
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<PagerStyle Mode="NumericPages" />
<Columns>
</Columns>
</MasterTableView>
</radG:RadGrid>
I won't post the code for all of the columns, because they're all done the same way, but here's the gist :-p
var hyperLinkColumn = new GridHyperLinkColumn
{
DataNavigateUrlFields = new[] { "TransactionID" },
Target = "_blank",
DataNavigateUrlFormatString = @"~/w1/SearchResultDetail.aspx?id={0}",
DataTextField = "Article Number",
HeaderText = "Article Number",
SortExpression = "Article Number",
UniqueName = "ArticleNumber"
};
rgResults.Columns.Add(hyperLinkColumn);
Well it seems I have found an answer to my question. I've tried tons of different things, but it looks like the one that did it was maybe referencing the wrong version.
I was using:
Telerik.WebControls.GridBoundColumn
instead of
Telerik.Web.UI.GridBoundColumn
for example.
Once I changed this around, the $find, and other ajax stuff started working. Maybe I was using the non-AJAX RadGrid before, which would explain it, I suppose...
But anyways, thanks to @rdmptn for all of your help!