Sorting gridview withe role and membership data

  • Thread starter Thread starter ferherra
  • Start date Start date
F

ferherra

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.
 
Back
Top