Autopostback on Dynamic Field Dropdown lists RRS feed

  • Question

  • User19825367 posted

    Hey folks,

    I want to have one of the automatically generated dropdown lists autopost back so I can get some required data.

    I have created a custom page and I have my detailsview with multiple dynamic fields but the dynamic field does not have a postback property? 

    Any ideas how I can maintian the nice dynamic retrieval of my foreign keys and have the functionality of a regular dropdown list?

     Thanks in advance.


    Sunday, December 7, 2008 8:49 PM


All replies

  • User-710964228 posted

     if you want to add the event on dynamically generated dropdown the you can use following code


    DropDownList _ddl = new DropDownList();
                    _ddl.AppendDataBoundItems = true;
                    for (int i = 0; i < 5; i++)
                        ListItem li = new ListItem();
                        li.Text = "ListItem" + i.ToString();
                        li.Value = i.ToString();
                    _ddl.AutoPostBack = true;
                    _ddl.SelectedIndexChanged += new EventHandler(Anyddl_SelectedIndexChanged);



    and  create the event "Anyddl_SelectedIndexChanged" for handling the selected index of the dynamically generated dropdown



    Monday, December 8, 2008 2:41 AM
  • User-330204900 posted

    My first approach would be to have a look a the FieldTemplate ForeignKey_Edit.ascx as this is where the dropdown list lives I'd then make a copy and modiy appropriatly and then set the UIHint for the column I wanted this feature on.

    If you wan any info on field Templates have a look here:

    1. Your First FieldTemplate.
    2. An Advanced FieldTemplate.
    3. A Second Advanced FieldTemplate.

    Hope this helps [:D]

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 8, 2008 4:36 AM
  • User19825367 posted

    Thanks Stephen,

     Good idea!


    Saturday, December 13, 2008 8:48 AM