This is a migrated thread and some comments may be shown as answers.

Displaying page index/counts

4 Answers 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jesse
Top achievements
Rank 1
Jesse asked on 07 Jul 2014, 07:34 PM
I put the following code in the RadGrid1_PageIndexChanged event:

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

4 Answers, 1 is accepted

Sort by
0
Jesse
Top achievements
Rank 1
answered on 07 Jul 2014, 07:40 PM
Oops, I cut off some of the first block of code. Doesn't really matter, since the code works, it's just not updating the label, but to prevent confusion, here's the full block:

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;
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Jul 2014, 05:10 AM
Hi Jesse,

You can use the PreRender event to set the label text to display the page details.

C#:
protected void rgrdExport_PreRender(object sender, EventArgs e)
{
 int showingRowsFrom = ((rgResults.CurrentPageIndex + 1) * rgResults.PageSize) - rgResults.PageSize + 1;
 int showingRowsTo;
 
 if ((rgResults.CurrentPageIndex + 1) == rgResults.PageCount)
 {
   showingRowsTo = GridSource.Tables[0].Rows.Count;
 }
 else
 {
   showingRowsTo = (rgResults.CurrentPageIndex + 1) * rgResults.PageSize;
 }
 
 string rowCount = string.Format("Displaying {0}-{1} of {2}", showingRowsFrom, showingRowsTo, GridSource.Tables[0].Rows.Count);
 lblResultsCountBottom.Text = lblResultsCountTop.Text = rowCount;
}

Thanks,
Princy
0
Jesse
Top achievements
Rank 1
answered on 08 Jul 2014, 04:08 PM
Thanks for the response :)

This works for the initial load, unfortunately, PreRender does not get fired on page change, so the label does not up date when I change pages. 

I did make a step in the right directions. I added a script manager to the page, so I'm not getting the $find is not defined javascript error anymore, but my grid variable is still coming up null...
0
Jesse
Top achievements
Rank 1
answered on 08 Jul 2014, 05:34 PM
On second thought, I set EnableAJAX="False" and this did the trick, so I'll go ahead and mark as answer. Thanks again, Princy!

It's not my favorite solution, since I have to turn off AJAX, but since there's so many issues with RadScriptManager, it seems to by my only options right now.
Tags
Grid
Asked by
Jesse
Top achievements
Rank 1
Answers by
Jesse
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or