+1-888-365-2779
Try Now
More in this section

Forums / Set-up & Installation / Users Grid

Users Grid

16 posts, 0 answered
  1. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    08 Aug 2007
    Link to this post
    hello,

    I have read the posts and the users guide to successfully add new fields to the membership class, ie: city, state, zip, middle name, phone number, etc for the users in the site.

    I have a need now to include a membership directory to visitors on the site.  I don't want to make the users log into the admin side.  So I'm trying to create a custom user control to do this.

    I started by copying the gridview from ~/SiteFinity/Admin/Users.aspx.

    What I can't seem to figure out is how that grid is databound.  I've tried looking into the base page, "AdminPage", but the source code isn't available.

    Is their any way to accomplish this?

    Additionally, because it's a gridview, I'd like to change some of the columns to include items from the membership class. An example might be: FName, LName, Address, PHone.

    I've searched the forums but haven't seen a request like this before....
    Thanks,
  2. Yasen
    Yasen avatar
    121 posts
    Registered:
    18 May 2013
    10 Aug 2007
    Link to this post
    Hello CHRIS,

    As far as we can understand you are trying to create a control that shows in the public part of your site a grid with all users or users chosen by some criteria. This is quite possible and one way to do that is to use the Data Source we use on the Users page. We are sorry it is not so well exposed, but we'll provide you with an example how you can use it.

    You can use a modification of this simple control :

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="PublicUserGrid.ascx.cs" Inherits="UserControls_PublicUserGrid" %> 
    <asp:GridView ID="GridView1" runat="server">  
    </asp:GridView> 


    And here is the code for it:

    using System;  
    using Telerik.Security.WebControls;  
     
    public partial class UserControls_PublicUserGrid : System.Web.UI.UserControl  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            UsersDataSource dataSource = new UsersDataSource();  
            dataSource.ID = "usersDataSource1";  
            GridView1.AllowPaging = true;  
            GridView1.PageSize = 20;  
            GridView1.DataSource = dataSource;  
            GridView1.DataBind();  
        }  


    However, the thing that delayed our response so much was the last part of your question.

    First of all, these custom fields are added to the profile of a user and are not stored with other membership info, so it's not so easy to get them from the Membership classes. It is quite possible, however, to create a custom data source that gets all the needed data from both Membership and Profile sections.

    Thanks to your request we were able to find some issues concerning the inablility for extension of our UserDataSource that will be revised for the next release. Till then you can use this temporary solution (please find the user control in the attached file).

    It basically creates a custom data source that uses the interface provided by Sitefinity for getting membership and profile data. You can modify the ExtUserInfo class in the control by adding the properties you need (UserName, FirstName and LastName are given as an example ). As you will see, it uses both membership and profile objects to provide the needed properties for the data grid.

    Thank you once again for the feedback it really helps to find our mistakes. Please accept our apology for the created troubles, we will be working on providing a tidier solution with our UsersDataSource for the future versions.



    All the best,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center


    Regards,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    10 Aug 2007
    Link to this post
    Yasen,

    Thank you for your feedback.  I will try your user control and let you know how things go. I know this was a bit of an odd request, so thank you for looking into it and creating the custom user control.

    You guys have a great product and I'm happy to help in any way.

    Thanks!
  4. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    31 Aug 2007
    Link to this post
    Yasen,

    The user control you created works like a champ!  Thank you!  Now that I have the public and admin side of things working, I need to dump our information into the database.

    I am now attempting to import an XLS DB into the user database.  Approx 500 rows. I haven't seen any posts in the forum, so I'm kinda stuck as to the best way to approach this.

    The XLS has the membership information (UserName, Email Address, FName, LName, and Password).  I'm assuming I'll need to write some sort of SQL Script, but I noticed the password is salted in the DB.  That presents a problem I'm looking for some help to overcome.

    Additionally, the XLS has custom profile information. Such as, Address, City, State, Zip, etc.  I know this information is stored in the telerik_UserMetaInfo table.  So I'm curious to see what you recommed the best practice is for importing this information.

    Of course from my previous post, you know that I've already setup our pages to allow the user to input this information (web.config & Sitefinity/Admin/CmsAdmin/MyProfile.aspx).  So we have everything ready to go from a user input perspective (for new users).  However, we're stuck trying to figure out how to import our existing 500 or so user's information.....

    For some reason I can't upload documents with this post, so here is a link to part of our XLS DB so you can get a better idea of what we are attempting to import.

    http://www.ascendio.com/chiomega.zip
    pswd: sitefinity


    Your help is always outstanding...I appreciate you looking into this for us.
    Thanks,
  5. Yasen
    Yasen avatar
    121 posts
    Registered:
    18 May 2013
    05 Sep 2007
    Link to this post
    Hi CHRIS mechsner,

    First, let me apologize for the delay of my response.

    You can easily import Excel information in an sql database using the SQL DTS, for an example please see this article. To insert users in the Telerik_Users table easily, you can set the password mode to "Clear" (which is 0 in the PasswordFormat field in the table) and then follow the rules for the other fields. To insert profile info in the telerik_UserMetaInfo however, is a much harder task to achieve using DTS.

    The other (and recommended) way you can achieve your goals is to use the membership/profile API provided by Sitefinity. The problem with it is that you have to be able to convert records in your .xls into .net objects. Here is an example how you can do that.


    Kind regards,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    07 Oct 2007
    Link to this post
    Yasen,

    Now that v3.1 is out for us to use, I was wondering what changes were put in place to affect the "UserDataSource". 

    There are a few other items that were planned to be fixed in v3.1 referenced in a post you did in this thread on
    8/10/2007 8:45:28 AM.

    Would you mind explaining how I can use the new functionality found in v3.1 to improve the control you submitted?
  7. Yasen
    Yasen avatar
    121 posts
    Registered:
    18 May 2013
    08 Oct 2007
    Link to this post
    Hi CHRIS mechsner,

    Actually, the improvements for providing data source for the users' grid were not included in v3.1 , we apologize for the inconvenience, they will be included in version 3.2. There is a chance that we manage to finish them for the service pack in a couple of weeks.

    For now the solution with this custom data source still works fine.

    Best wishes,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    11 Oct 2007
    Link to this post
    Hi Yasen, your help has been outstanding and very much appreciated.  I wanted to provide the code I used to import my XLS of students.  It shows how to use the MembershipProvider API.  I ended up importing the XLS into a small Access DB, seemed easier to do.

    I just put the logic into a blank page, and when executed, it imports the students.
    Here is the .aspx file

    1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddUsers.aspx.cs" Inherits="AddUsers" %> 
    2 
    3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    4 
    5<html xmlns="http://www.w3.org/1999/xhtml" > 
    6<head runat="server"
    7    <title>Untitled Page</title> 
    8</head> 
    9<body> 
    10    <form id="form1" runat="server"
    11    <div> 
    12        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/Database2.mdb" 
    13            SelectCommand="SELECT * FROM [UT]"></asp:AccessDataSource> 
    14     
    15    </div> 
    16    </form> 
    17</body> 
    18</html> 
    19 
    20 


    And here is the codebehind....

    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Collections; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; 
    using Telerik.DataAccess; 
    using Telerik.Security; 
     
    public partial class AddUsers : System.Web.UI.Page 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            //read xls file 
            DataView dv = AccessDataSource1.Select(DataSourceSelectArguments.Empty) as DataView; 
            DataTable dt = dv.ToTable(); 
            if ( dt.Rows.Count > 0 )  
            { 
                int i = 0; 
                foreach (DataRow dr in dt.Rows ) 
                { 
                    i++; 
                    try 
                    { 
                        MembershipUser user = Membership.CreateUser(dr["Login"].ToString(), dr["Login"].ToString(), dr["Email"].ToString()); 
                        Roles.AddUserToRole(dr["Login"].ToString(), "Students"); 
                        ProfileCommon profile = (ProfileCommon)ProfileCommon.Create(dr["Login"].ToString()); 
                        profile.Address = dr["Address"].ToString(); 
                        if (dr["Birthday"].ToString() != ""
                            profile.BirthDay = DateTime.Parse(dr["Birthday"].ToString()).ToString("d"); 
                        else 
                        { 
                            profile.BirthDay = ""
                        } 
                        profile.CellPhone = dr["Cellphone"].ToString(); 
                        profile.City = dr["City"].ToString(); 
                        profile.FirstName = dr["FirstName"].ToString(); 
                        profile.HomeAddress = dr["Permanent Address"].ToString(); 
                        profile.HomeCity = dr["Permanent City"].ToString(); 
                        profile.HomePhone = dr["Phone"].ToString(); 
                        profile.HomeState = dr["Permanent State"].ToString(); 
                        profile.HomeZip = dr["Permanent Zip"].ToString(); 
                        if (dr["Membership Date"].ToString() != ""
                            profile.InitiationYear = DateTime.Parse(dr["Membership Date"].ToString()).ToString("d"); 
                        else 
                            profile.InitiationYear = ""
                        profile.LastName = dr["Lastname"].ToString(); 
                        profile.MiddleName = dr["Middlename"].ToString(); 
                        profile.Position = "Members"
                        profile.State = dr["State"].ToString(); 
                        profile.Zip = dr["Zip"].ToString(); 
                        profile.Save(); 
                    } 
                    catch (Exception exc) 
                    { 
                        Membership.DeleteUser(dr["Login"].ToString()); 
                         
                        Response.Write("ERROR: " + dr["FName"].ToString() + " " + dr["LName"].ToString()); 
                    }                 
                }             
                Response.Write("total : " + i.ToString());             
            } 
            AccessDataSource1.Dispose();         
        } 

  9. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    11 Oct 2007
    Link to this post
    Yasen, forgot to ask a question, in the custom user control you provided above, I substituted your GridView control for a RadGrid control.  I kept all the properties the same, except I enabled Ajax, paging, and sorting.

    I'm getting an error, and was wondering if you had any ideas?

     maxRows 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
     
    Exception Details: System.ArgumentException: maxRows 
     
    Source Error: 
     
    Line 466:                    break; 
    Line 467:                default: 
    Line 468:                    result = this.Manager.GetAllUsers(arguments.StartRowIndex, arguments.MaximumRows, arguments.SortExpression, out totalRows); 
    Line 469:                    break; 
    Line 470:            } 
     
     
    Source File: d:\IIS\Clients\CMS_SiteFinity_Sites\ChiOmega\UserControls\SummaryUserInfo_Officers.ascx.cs    Line: 468 
     
    Stack Trace: 
     
    [ArgumentException: maxRows] 
       Telerik.Security.UserManager.GetAllUsers(Int32 from, Int32 maxRows, String sortExpr, Int32& totalRows) +308 
       ChiOmega.Officers.ExtUsersDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) in d:\IIS\Clients\CMS_SiteFinity_Sites\ChiOmega\UserControls\SummaryUserInfo_Officers.ascx.cs:468 
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17 
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149 
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70 
       Telerik.WebControls.RadGrid.DataBind() +18 
       ChiOmega.Officers.UserControls_SummaryUserInfo_Officers.populateGrid() in d:\IIS\Clients\CMS_SiteFinity_Sites\ChiOmega\UserControls\SummaryUserInfo_Officers.ascx.cs:25 
       ChiOmega.Officers.UserControls_SummaryUserInfo_Officers.Page_Load(Object sender, EventArgs e) in d:\IIS\Clients\CMS_SiteFinity_Sites\ChiOmega\UserControls\SummaryUserInfo_Officers.ascx.cs:17 
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34 
       System.Web.UI.Control.OnLoad(EventArgs e) +99 
       System.Web.UI.Control.LoadRecursive() +47 
       System.Web.UI.Control.AddedControl(Control control, Int32 index) +2068021 
       System.Web.UI.ControlCollection.Add(Control child) +146 
       Telerik.Cms.Web.InternalPage.CreateChildControls() +1633 
       System.Web.UI.Control.EnsureChildControls() +87 
       System.Web.UI.Control.PreRenderRecursiveInternal() +41 
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360 
     
     
    Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210 

  10. Yasen
    Yasen avatar
    121 posts
    Registered:
    18 May 2013
    11 Oct 2007
    Link to this post
    Hello CHRIS mechsner,

    Thank you for sharing your code.

    The issue with using the radGrid is that the ExecuteSelect method from the View class (ExtUsersDataSourceView in our case) is called with Empty arguments (System.Web.UI.DataSourceSelectArguments.Empty). So the pageSize property (max rows) is 0. The thing is that RadGrid does not use DataSourceSelectArguments so an "Empty" instance is created and an exception is thrown as maxRows has to be > 0.

    For now you can manually change the MaximumRows property value in the ExecuteSelect method in ExtUsersDataSourceView. Here is an example how to do that:

    (I assume you are using the PublicUserControl that is available for download)
    protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)  
      {  
        arguments.MaximumRows = 20;  
        int totalRows = 0;  
        ... 

    That should be enough to get the control to work with RadGrid.

    Hope this solves your case, if you have any other questions you are always welcome to ask.

    Sincerely yours,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  11. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    16 Oct 2007
    Link to this post
    Yasen, your quick fix worked great. Thank you for always having the 'right' answers! Please forgive me, I'm still trying to grasp everything that is going on in the custom datasource you built.

    My new problem is that I can't get the Sort and Paging features to work properly using the RadGrid.

    If I attempt to sort by "Phone", It gives me an error stating that "phone" doesn't exists in the data source

     Invalid column name 'Title'. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
     
    Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'Title'. 
     
    Source Error: 
     
    Line 451:                    break; 
    Line 452:                default: 
    Line 453:                    result = this.Manager.GetAllUsers(arguments.StartRowIndex, arguments.MaximumRows, arguments.SortExpression, out totalRows); 
    Line 454:                    break; 
    Line 455:            } 
     
     
    Source File: d:\IIS\Clients\CMS_SiteFinity_Sites\ChiOmega\UserControls\SummaryUserInfo_Officers.ascx.cs    Line: 453  


    Please forgive my ignorance, but do you have any examples/ideas for how to implement paging and sorting with the custom solution you've provided?

    I have the PageSize property set to 15, but it doesn't appear to be reading that property when i set it.

    Thank you again for all your terrefic support!
    Chris

    here is a link to my file for download.
  12. Yasen
    Yasen avatar
    121 posts
    Registered:
    18 May 2013
    17 Oct 2007
    Link to this post
    Hello CHRIS mechsner,

    This exception is not surprising as the GetAllUsers method expects a valid column name and "Title" is not a column in the Users table.

    You have to manually implement sorting and paging in the ExecuteSelect method in the ExtUsersDataSourceView. A possible way is to use List instead of IList and take advantage of the Sort method. You'll just need to write your custom comparer (class that implements IComparer interface).

    A similar thing could be done for paging as well. If you have problems doing that, feel free to contact us again.

    Best wishes,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  13. mexner
    mexner avatar
    98 posts
    Registered:
    06 Apr 2006
    18 Oct 2007
    Link to this post
    Hi Yasen,

    What you said makes sense.  I'm still having a bit of a learning curve, and need some help implementing your ideas.

    Do you have any code examples?  The paging aspect is most important.

    Thanks!
  14. Yasen
    Yasen avatar
    121 posts
    Registered:
    18 May 2013
    18 Oct 2007
    Link to this post
    Hello CHRIS mechsner,

    You can find attached the updated control. Note the following facts:
    • Paging works properly
    • Sorting by Email works as email is from the Membership properties (not part of the Profile)
    • Sorting for other pages works only for the records in that page. That is because the custom sorting functionality is added after the current part of the collection is taken. To allow full sorting by these columns you have to get all users, then perform the sort and return only part of the collection.
    • Page size functionality works properly now.

    This sample control should be useful for you to write sorting functionality. If you have any other problems, feel free to contact us again.

    Kind regards,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  15. UI Crew
    UI Crew avatar
    99 posts
    Registered:
    24 Sep 2012
    15 Jun 2009
    Link to this post
    Hi,

    Just after an update on the Usersdatasource issue. Would like to extend the searchField in SF Admin Manager Users to allow for admin users to search users by profile peoperties such as First Name - has the Usersdatasource been fixed now (version 3.6) and is this possible.

    Thanks

    Seth
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    15 Jun 2009
    Link to this post
    Hello Seth Cleaver,

    The Membership class supports FindUsersByEmail() and FindUsersByName() methods. You need to implement your custom provider and logic depending on your needs. For getting and setting profile property is used ProfileBase class . In this way you need to get the Profile data, for example  Profile.GetProfile() and add it to list to populate Membership collection.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
16 posts, 0 answered