Copied to clipboard

Flag this post as spam?

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


  • SC Digital Services Team 104 posts 171 karma points
    Jan 11, 2013 @ 13:20
    SC Digital Services Team
    0

    Dynamically update a list based on prevalues from a dropdown datatype

    I've built a custom datatype that creates a list of features for a group of venues (in this case, the libraries in our area), which, for the most part, is working properly.

    The trouble I'm having is getting a field in the user control to dynamically update with the prevalues retrieved from another datatype. Currently the users pick the icon list, then manually save & reload the data type before the prevalues appear in the "Icon type" drop-down field...

    Do I need to add a condition to pick up on a postback, and, if so, how do I do this?

    The code for the "Add venue features" section is below...


    public class VenueItems : umbraco.cms.businesslogic.datatype.DataEditorSettingType
    {
    private Panel p = new Panel();
    private TextBox tb = new TextBox();
    private DropDownList ddl = new DropDownList();

    public override string Value
    {
    get
    {
    return tb.Text;
    }
    set
    {
    tb.Text = value;
    }
    }

    public override System.Web.UI.Control RenderControl(DataEditorSetting sender)
    {
    tb.CssClass = "itemsAdded";
    tb.ID = sender.GetName() + "_values";

    ddl.CssClass = "newItemClass";
    ddl.ID = sender.GetName() + "_classes";

    // get ID of this data type from querystring
    int dataTypeId;
    if (Int32.TryParse(HttpContext.Current.Request["id"], out dataTypeId))
    {
    // get all data editor settings for this data type
    DataEditorSettingsStorage des = new DataEditorSettingsStorage();
    var settings = des.GetSettings(dataTypeId);
    Setting<string, string> thisSetting = settings.Find(s => s.Key == this.Prevalues[0]);
    if (thisSetting.Key != null)
    {
    int selectedDtId;
    if (Int32.TryParse(thisSetting.Value.ToString(), out selectedDtId))
    {
    var prevalues = PreValues.GetPreValues(selectedDtId);
    if (prevalues.Count > 0)
    {
    for (int i = 0; i < prevalues.Count; i++)
    {
    var prevalue = (PreValue)prevalues[i];
    if (!String.IsNullOrEmpty(prevalue.Value))
    {
    ddl.Items.Add(new ListItem(prevalue.Value, prevalue.DataTypeId.ToString()));
    }
    }
    }
    else
    {
    ddl.Items.Add("Failed to find the icon list...");
    }
    }
    }
    else
    {
    ddl.Items.Add("Failed to find the icon list...");
    }
    }

    string html1 = "<div class='values'>";
    html1 += "</div>";
    html1 += "<div class='venueItemsInputs'>";
    html1 += "<hr/>";
    html1 += "<span class='inputLabel'>Icon type:</span>";

    string html2 = "<span class='inputLabel'>Item:</span>";
    html2 += "<input type='text' class='newItemInput' /><br/>";
    html2 += "<span class='inputLabel'>Detail:</span>";
    html2 += "<input type='text' class='newItemDetailInput' />";
    html2 += string.Format(" <a onclick=\"valuesCustomControlAddValue(this); return false;\" href='#' class='Add'>Add Item</a>");
    html2 += "</div>";

    p.Controls.Add(new System.Web.UI.LiteralControl("<div class='itemsCustomControl'>"));
    p.Controls.Add(new System.Web.UI.LiteralControl(html1));
    p.Controls.Add(ddl);
    p.Controls.Add(new System.Web.UI.LiteralControl("<br/>"));
    p.Controls.Add(new System.Web.UI.LiteralControl(html2));
    p.Controls.Add(tb);
    p.Controls.Add(new System.Web.UI.LiteralControl("</div>"));


    System.Web.UI.Page page = (System.Web.UI.Page)HttpContext.Current.Handler;

    page.ClientScript.RegisterClientScriptInclude(
    "Shropshire.Web.DESettingType.VenueItems.Resources.VenueItems.js",
    page.ClientScript.GetWebResourceUrl(typeof(VenueItems), "Shropshire.Web.DESettingType.VenueItems.Resources.VenueItems.js"));

    HtmlHead head = (HtmlHead)page.Header;
    HtmlLink link = new HtmlLink();
    link.Attributes.Add("href", page.ClientScript.GetWebResourceUrl(typeof(VenueItems), "Shropshire.Web.DESettingType.VenueItems.Resources.VenueItems.css"));
    link.Attributes.Add("type", "text/css");
    link.Attributes.Add("rel", "stylesheet");
    head.Controls.Add(link);

    return p;
    }
    }

     

  • SC Digital Services Team 104 posts 171 karma points
    Jan 15, 2013 @ 11:40
    SC Digital Services Team
    0

    *bump*

  • Comment author was deleted

    Jan 17, 2013 @ 13:13

    Maybe the findcontrol method could be usefull here http://msdn.microsoft.com/en-us/library/31hxzsdw.aspx

    Or do it with some ajax...

  • SC Digital Services Team 104 posts 171 karma points
    Jan 17, 2013 @ 13:32
    SC Digital Services Team
    0

    Thanks again Tim! I'll have a play this afternoon & see if I can get it working.

  • Comment author was deleted

    Jan 17, 2013 @ 14:23

    Not sure if this is of any use http://umbraco.miketaylor.eu/2011/02/10/creating-a-custom-data-editor-setting-type/

    There's also some connection between different settings 

  • SC Digital Services Team 104 posts 171 karma points
    Jan 17, 2013 @ 14:42
    SC Digital Services Team
    0

    Thanks - the original idea for our datatype came about because of that article & the example on your site - http://www.nibble.be/?p=96

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft