Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • saif 68 posts 88 karma points
    Jan 23, 2012 @ 16:38
    saif
    0

    Member Type property Dropdownlist databinding

    Hi All,

    I have a table named school with prepopulated data.

    I created Member type Headteacher with different properties SchoolName (dropdownlist) and Town (text string) ,etc...

    I want to create  Members but I want to prepopulate the school details Please could you give me any idea how to do that.

    I can do that in c# or web application but no idea how to bind data with Member type properties.

     

    any help would be appreciated.

     

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 23, 2012 @ 16:49
    Jeroen Breuer
    0

    You can use Member.New event. There you can set the properties which means that after creating a member the properties can be prepopulated. More info about events here: http://www.richardsoeteman.net/2009/02/22/UmbracoV4EventsDemo.aspx

    Jeroen

  • Rodion Novoselov 694 posts 859 karma points
    Jan 23, 2012 @ 16:54
    Rodion Novoselov
    0

    Hi. I think the most ultimate way to achieve this would be to create a custom umbraco data type that will be rendered in the member editor with a dropdown list populated by results of a query to the school database. However, I suppose that if the strict actuality of data is not a big issue then you could simply use an inbuild umbraco dropdown list datatype and time to time to sync its prevalues between the school database and your umbraco instance.

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 23, 2012 @ 16:57
    Anthony Candaele
    0

    Is there a special reason why you fetch the prevalues from a sql table?

    Otherwise you can define an Umbraco Datatype with the prevalues, and access the prevalues using the Umbraco.Library.GetPreValues(datatype id) method.

    Anthony

  • saif 68 posts 88 karma points
    Jan 23, 2012 @ 17:04
    saif
    0

    Actually, there is a huge table of schools' names and it is maintained somewhere else. My job is to replicate the table from that database and populate it in dropdownlist in order to let end user to select from a populated list.

    anyway thanks for your suggestion I am sure I can try this one somewhere in my project.

    kind regards

    saif

  • saif 68 posts 88 karma points
    Jan 23, 2012 @ 17:16
    saif
    0

    Hi Rodion,

    Please could you explain a little bit more on how to populate the drop down list ie basically where do I write the query. Sorry if this is very basic question.

    thanks

  • Rodion Novoselov 694 posts 859 karma points
    Jan 23, 2012 @ 17:25
    Rodion Novoselov
    0

    You can make use of the umbraco usercontrol wrapper as it's the simplest way to create a custom datatype. Here is detailed explanation about how to do it: http://www.nibble.be/?p=24. In two words - you place on your underlying user control (i.e the usercontrol to wrap) anything you like - in your case it would be a dropdown list, then you populate this list by any mean you can use in a regular asp.net application (ADO.NET, EF, etc). The only umbraco-specific thing you will need to implement is the Value property of the IUsercontrolDataEditor interface. Then you place this control in the ~/usercontrols/ folder and create a new umbraco datatype choosing the "umbraco usercontrol wrapper" as its base datacontrol and pointing your control created earlier as its parameter. That's it and you will be able to create document type properties of this datatype.

  • saif 68 posts 88 karma points
    Jan 24, 2012 @ 12:17
    saif
    0

    Hi Rodion,

    I could not implement IUsercontrolDataEditor interface even I have added Umbraco.dll and umbraco.editorControls.dll in my local project.

    But when I created the same control (I did not have any propblem to implement the interface) in Umbrao-> Usercontrol directory. Then I created new datatype and when I chose the usercontrol (SchoolList) from setting section It pulls the home page of mywebsite.

    Am I missing some steps?

     

     

  • Rodion Novoselov 694 posts 859 karma points
    Jan 24, 2012 @ 13:10
    Rodion Novoselov
    2

    Well, here's my sample that's done for a couple of minutes.

    SchoolPicker.ascx file:

    <%@ Control Language="C#" AutoEventWireup="true"
        CodeFile="SchoolPicker.ascx.cs" Inherits="usercontrols_SchoolPicker" %>
    
    <asp:DropDownList ID="ddlSchool" runat="server" DataTextField="Name" DataValueField="Id" AppendDataBoundItems="true">
      <asp:ListItem Text="Select school:" Value=""/>
    </asp:DropDownList>

    SchoolPicker.ascx.cs file:

    using System.Web.UI;
    using umbraco.editorControls.userControlGrapper;
    
    public partial class usercontrols_SchoolPicker : UserControl, IUsercontrolDataEditor
    {
        protected void Page_Load()
        {
            if (!IsPostBack)
            {
                // below should be your code to populate the list 
                // from the database
                ddlSchool.DataSource = new[]{
                    new { Id = 1, Name = "School 1" },
                    new { Id = 2, Name = "School 2" },
                    new { Id = 3, Name = "School 3" }
                };
                ddlSchool.DataBind();
            }
        }
    
        public object value
        {
            get { return ddlSchool.SelectedValue; }
            set
            {
                ddlSchool.SelectedValue = (value != null)? value.ToString(): string.Empty;
            }
        }
    }

    Than I place both files under ~/usercontrols/ folder of Umbraco.

    Create a new DataType:

    Add a property of the new "School Picker" datatype to some document type. That's it - everything works:

    If you want to build your control as a separate project you will need to reference the umbraco.editorControls.dll assembly since it's the one where the declaration of the IUsercontrolDataEditor interface resides.

  • saif 68 posts 88 karma points
    Jan 24, 2012 @ 13:12
    saif
    0

    Done it! thank you Rodion.

     

  • saif 68 posts 88 karma points
    Jan 24, 2012 @ 13:17
    saif
    0

    Thanks a lot Rodion for source code although I have done it already but the code you have written is absolutly fantastic.

     

  • saif 68 posts 88 karma points
    Jan 24, 2012 @ 13:34
    saif
    0

    Really Interested to use Razor.

    I have written classes in c# to acces database and to process business logic.

    My question is If I write down all these classes in razor.cshtml will it improve the efficiency.

    Or

    These classe should be as it is and I just need to call them in razor.cshtml pages. (Might be I still dont understand when and where to use razor)

    your thoughts would be really helpful and appreciated.

     

     

     

  • Rodion Novoselov 694 posts 859 karma points
    Jan 24, 2012 @ 13:51
    Rodion Novoselov
    0

    I don't think that's easy or even achievable. Umbraco backoffice is locked to use WebForms page model that's completely different from WebPages. Also, I think that there's no reason to bother much about backoffice component performance - it's an admin part of the site and not supposed to be highly-loaded. When it comes to the public front-end part of the site there can be a good point to use razor instead of webforms controls (clean HTML, no viewstate, etc), but not in the backoffice.

  • saif 68 posts 88 karma points
    Jan 24, 2012 @ 14:43
    saif
    0

    Thank you Rodion it is much clearer now.

  • saif 68 posts 88 karma points
    Jan 24, 2012 @ 17:11
    saif
    0

    Hi Rodion,

    Here is my code I have written.

    I wonder how to save this schoolId into database.

     

    public partial class _Default : System.Web.UI.Page,umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
        {
          
            HSStruct theDoc;
            public string schoolid;
            public object value
            {
                get
                {
                    return schoolid;
                }
                set
                {
                    schoolid = (value != null) ? value.ToString() : string.Empty;
                }
            }

            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    LoadSchoolList();
                }      
            }
           
            public void LoadSchoolList()
            {
                cSchool schobj = new cSchool();
                theDoc = schobj.GetSchoolsList();
                ddl_SchoolsList.DataTextField = "name";
                ddl_SchoolsList.DataValueField = "dfesNumber";
                ddl_SchoolsList.DataSource = theDoc.DT;
                ddl_SchoolsList.DataBind();
            }

            protected void ddl_SchoolsList_SelectedIndexChanged(object sender, EventArgs e)
            {
              schoolid=  ddl_SchoolsList.SelectedValue;
            }

  • Rodion Novoselov 694 posts 859 karma points
    Jan 24, 2012 @ 17:21
    Rodion Novoselov
    0

    Saif, I'm a bit confused. For more clarity - I supposed we were talking about a custom datatype that would use an external database table as a lookup list, right? 

  • saif 68 posts 88 karma points
    Jan 24, 2012 @ 17:50
    saif
    0

    I have created a member type Headteacher with two extra properties DFES number (dropdownlist) and SchoolName (textstring). the schoolName is saved but dfes doesnot.

    DFES numbers comes from table named schooldetails.(this is why I had created the control and I assumed that selected value would be saved automatically in database but this didnot)

    whenever admin registers a new memeber as a headteacher then he/she needs to select which school they belong to.

    Sorry If I am making it too complex.

     

     

  • saif 68 posts 88 karma points
    Jan 25, 2012 @ 07:12
    saif
    0

    Hi Rodion,

    I wonder, Do I need to use cutomize user registration control for above scenario.

    or

    Simply I need to create members with additional properties as profile details.

    regards

Please Sign in or register to post replies

Write your reply to:

Draft