This project is read-only.

Paging on User Management grid

Topics: Developer Forum, User Forum
Mar 18, 2008 at 2:40 AM
Has anyone been able to get paging to work with the GridView control that displays the current list of users (under Administration > User Management)? I have done all that I thought was necessary, but paging simply will not work for me. Here's a summary I what I have done:

- Set AllowPaging="true" in GridView control. Also set PageSize to a small number (ex: 5).

Changed the ObjectDataSource as follows:

<asp:ObjectDataSource runat="server" ID="srcUsersGrid" TypeName="MyWebPagesStarterKit.Providers.CustomXmlMembershipProvider" EnablePaging="true" SelectCountMethod="GetUserCount" SelectMethod="GetUserPage" MaximumRowsParameterName="maxRows" StartRowIndexParameterName="startIndex" ></asp:ObjectDataSource>

The signature for my SelectMethod is as follows:

public MembershipUserCollection GetUserPage( int maxRows, int startIndex )

This method does indeed get invoked, but maxRows and startIndex are always 0 and as such the return member collection is always empty. Any ideas as to what would cause these two parameters to always be 0?

Thanks,

Tony
Mar 18, 2008 at 5:06 AM
Edited Mar 18, 2008 at 5:18 AM
You must edit in
<asp:GridView runat="server" DataKeyNames="Guid" ID="gvNewsList" AutoGenerateColumns="False" OnRowCommand="gvNewsList_RowCommand" OnRowDataBound="RowBound" AllowPaging="True" OnPageIndexChanging="ChangingPage">

----------------
protected void RowBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView CurRow = (DataRowView)e.Row.DataItem;
if (e.Row.DataItemIndex < 3)
((Label)e.Row.Cells1.Controls5).Text = ((string)CurRow"NewsText").Substring(0, 400) + "...<br><br>";
else
((Label)e.Row.Cells1.Controls5).Text = "";
if (((string)CurRow"Link").Equals(string.Empty))
((Image)e.Row.Cells1.Controls3).Visible = false;
else
{
((Image)e.Row.Cells1.Controls3).Attributes.Add("onclick", "javascript:{window.open('" + (string)CurRow"Link" + "');}");
((Image)e.Row.Cells1.Controls3).Style.Add("cursor", "hand");
}
((LinkButton)e.Row.Cells1.Controls1).CommandArgument = e.Row.DataItemIndex.ToString();
}
}

protected void ChangingPage(object sender, GridViewPageEventArgs e)
{
gvNewsList.PageIndex = e.NewPageIndex;
}
Mar 19, 2008 at 2:35 AM
Thanks for the reply, hazardvn but it turns out the solution was something quite unexpected (for me, at least). First, I was overcomplicating things in that I didn't need to implement custom paging. The default paging will work fine. No changes for paging should be made to the objectdatasource. What I found in debugging the page is that the gridview AllowPaging property was being ignored. Even when set to true, the property was false when evaluated at a breakpoint during debugging. Iseems to work fine by setting it to true programmatically in Page_Load:

if( !IsPostBack )
gvUsers.AllowPaging = true;