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.
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.
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.
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.
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.
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.
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, 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?
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.
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.
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
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.
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
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
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
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.
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?
Well, here's my sample that's done for a couple of minutes.
SchoolPicker.ascx file:
SchoolPicker.ascx.cs file:
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.
Done it! thank you Rodion.
Thanks a lot Rodion for source code although I have done it already but the code you have written is absolutly fantastic.
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.
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.
Thank you Rodion it is much clearer now.
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;
}
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?
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.
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
is working on a reply...