By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

Sorting gridview withe role and membership data

P: n/a
Hi,
Hope someone can help...

I databind my gridview (asp.net 2.0) like this:
GridView1.DataSource = Membership.GetAllUsers();
(MembershipUserCollection)
GridView1.DataBind();

In the GridView1_RowDataBound eventhandler
I'm getting the user role for each user (each user will only have and
only role) and add the text to a grid column like this:

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string userName = e.Row.Cells[0].Text;
MembershipUser user = Membership.GetUser(userName);

string[] userRoles =
Roles.GetRolesForUser(user.UserName);
if (userRoles.Length 0)
e.Row.Cells[1].Text = userRoles[0]; //Column 1 is
used to display de user Role
else
e.Row.Cells[1].Text = "No Role";

}//end if (e.Row.RowType == DataControlRowType.DataRow)

}

I need to enable the gridview to sort by user role. The questions are:
how to combine the information of Membership.GetAllUsers() and
Roles.GetRolesForUser(user.UserName) into a DataSet,objectdatasource or
some object that will allow me to enable the gridview to sort by role?
I would like to use the objects .net 2.0 has or do I have to do my own
stored procedure?

One more thing I would like to know if there is way to use
objectdatasource(I haven't used this object, but in some post I read it
can help but doesn't says in which way)
control with Membership.GetAllUsers();? or if it is posible to change
Membership.GetAllUsers() to a dataset? (All these is to allow sorting
in a gridview)
Thanks.

Jul 14 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.