Umbraco 6.** - sorry couldnt find a forum for this version.
I have created a datatype called Colors and added Text and Value as below
Red 1
Blue 2
Yellow 3
Green 4
Under Document types i create a new property and set the Type to colors.
Create a content page using the doc type above and i can see the colors i added.
How could i use this data type with a user control dropdown list?
You can get drop down list value by using Prevalues like below.
List<string> li = new List<string>();
var values = PreValues.GetPreValues(DataTypeId);
foreach (DictionaryEntry de in values)
{
PreValue pv = (PreValue)de.Value;
// Here you will get id and value of the data type drop down list
// pv.Id
// pv.value
}
private void BindColors()
{
List<string> li = new List<string>();
var values = PreValues.GetPreValues(1234);
var ddlColors = (DropDownList)lv.FindControl("ddlColors");
foreach (DictionaryEntry de in values)
{
PreValue pv = (PreValue)de.Value;
// Here you will get id and value of the data type drop down list
ddlColors.DataTextField = pv.Value;
ddlColors.DataValueField = pv.Id.ToString();
}
ddlColors.DataSource = values;
ddlColors.DataBind();
}
the error message i receive is "DataBinding: 'System.Collections.DictionaryEntry' does not contain a property with the name 'Blue'."? Any thoughts
Can you please check the ID of the data type that it is proper or not?
And try with the below code.
private void BindColors()
{
List<string> li = new List<string>();
var values = PreValues.GetPreValues(1234);
var ddlColors = (DropDownList)lv.FindControl("ddlColors");
foreach (DictionaryEntry de in values)
{
PreValue value = (PreValue)de.Value;
ListItem li = new ListItem();
li.Text = value.Value;
li.Value = value.Id.ToString();
ddlColors.Items.Add(li);
}
}
Data type with DDL
Umbraco 6.** - sorry couldnt find a forum for this version.
I have created a datatype called Colors and added Text and Value as below
Red 1 Blue 2 Yellow 3 Green 4
Under Document types i create a new property and set the Type to colors. Create a content page using the doc type above and i can see the colors i added.
How could i use this data type with a user control dropdown list?
Hi J,
You can get drop down list value by using Prevalues like below.
Hope this will help you.
Regards,
Urvish Mandaliya
My code is
the error message i receive is "DataBinding: 'System.Collections.DictionaryEntry' does not contain a property with the name 'Blue'."? Any thoughts
Hi J,
Can you please check the ID of the data type that it is proper or not?
And try with the below code.
Hope this will help.
Regards,
Urvish Mandaliya
is working on a reply...