468,272 Members | 1,984 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

enable paging to a custom membership gridview

JustRun
127 100+
Hi,

This is the first time to work with ASP.NET.
I had a customized membership gridview, the problem is i can't enable paging feature or sorting.


1 protected DataSet MyGetAllUsers()
2 {
3 DataSet ds = new DataSet();
4
5 dt = ds.Tables.Add("Users");
6 muc = Membership.GetAllUsers();
7
8 dt.Columns.Add("UserName", Type.GetType("System.String"));
9 dt.Columns.Add("Email", Type.GetType("System.String"));
10 dt.Columns.Add("CreationDate", Type.GetType("System.DateTime"));
11 dt.Columns.Add("IsOnline", Type.GetType("System.Boolean"));
12 dt.Columns.Add("IsLockedOut", Type.GetType("System.Boolean"));
13
14 foreach (MembershipUser mu in muc)
15 {
16 DataRow dr;
17 dr = dt.NewRow();
18 dr["UserName"] = mu.UserName;
19 dr["Email"] = mu.Email;
20 dr["CreationDate"] = mu.CreationDate;
21 dr["IsOnline"] = mu.IsOnline;
22 dr["IsLockedOut"] = mu.IsLockedOut;
23
24 dt.Rows.Add(dr);
25 }
26 return ds;
27 }
28
29 protected void btnShowAll_Click(object sender, System.EventArgs e)
30 {
31 grdUsers.Visible = true;
32 MyGetAllUsers();
33 grdUsers.DataSource = dt;
34 grdUsers.DataBind();
35 }

This code is working so good, I've tried to put the following code to enable paging and sorting, it didn't fire any error But also it didn't give me any result:

private string ConvertSortDirectionToSql(SortDirection sortDireciton)
{
string newSortDirection = String.Empty;

switch (sortDireciton)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;

case SortDirection.Descending:
newSortDirection = "DESC";
break;
}

return newSortDirection;
}

protected void grdUsers_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdUsers.PageIndex = e.NewPageIndex;
grdUsers.DataBind();
}

protected void grdUsers_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = grdUsers.DataSource as DataTable;

if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

grdUsers.DataSource = dataView;
grdUsers.DataBind();
}
}



Any ideas?
Apr 9 '08 #1
0 979

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Wiktor Zychla [C# MVP] | last post: by
3 posts views Thread by Marc Grutte | last post: by
7 posts views Thread by =?Utf-8?B?SmVmZiBCZWVt?= | last post: by
5 posts views Thread by =?Utf-8?B?Z3V5?= | last post: by
1 post views Thread by John A Grandy | last post: by
1 post views Thread by Danny Ni | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.