How could I get the value in code behind and show the text in dropdownlist?

  1. #1

    How could I get the value in code behind and show the text in dropdownlist?

    Hi,everyone.
    I want to show the text in the dropdownlist and get the value which was selected in the code behind.
    I write the code like this,but it doesn't work.
    EXT.NET 2.5.2


    @model Sys.Sys_Organization
     @(X.FormPanel()
            .ID("PanelList")
            .Frame(true)
            .AutoScroll(true).JsonSubmit(true)
            .BodyPadding(10)
            .Layout(LayoutType.Fit)
            .FieldDefaults(fd => { fd.LabelWidth = 110; fd.LabelStyle = "color:green;padding-left:4px;"; })
            .Items(
                X.Container()
                    .Layout(LayoutType.HBox)
                    .Items(
                        X.FieldSet()
                            .Flex(1)
                            .Title("Information")
                            .Layout(LayoutType.Anchor)
                            .DefaultAnchor("100%").MarginSpec("0 0 10")
                            .Defaults(X.Parameter().Name("HideEmptyLabel").Value("false").Mode(ParameterMode.Raw))
                            .Items(
                                
                                X.DropDownFieldFor(model => model.ParentId,true)
                                        .Text(Model.ParentOrg.FullName)
                                        .FieldLabel("parentTree")
                                        .EmptyText("--- select ---")
                                        .Editable(false)
                                        .Mode(DropDownMode.ValueText)
                                        .TriggerIcon(TriggerIcon.SimpleArrowDown)
                                            .Component(treePanel => 
                                                treePanel.Add(Html.X().TreePanel()
                                                    .Height(300)
                                                    .Width(500)
                                                    .MinWidth(500)
                                                    .RootVisible(false)
                                                    .SelectionModel(selectionmodel => selectionmodel.Add(Html.X().TreeSelectionModel().Mode(SelectionMode.Single)))
                                                   
                                                    .Store(
                                                            Html.X().TreeStore()
                                                                .Proxy(
                                                                    Html.X().AjaxProxy()
                                                                        .Url(Url.Action("GetNodes"))
                                                                )
                                                                .Root(
                                                                    Html.X().Node().NodeID("Root")
                                                                )                    
                                                        )
                                                        .Listeners(l => {
                                                            l.ItemClick.Handler = @"this.dropDownField.setValue(record.data.id, record.data.text, true);";
                                                                l.AfterRender.Handler = "this.getRootNode().expand(true);";
                                                                l.AfterRender.Delay = 50;
                                                            })
                                                    )          
                                                
                                                )
                              
                               
                                ) 
                       
                         )
                     )
            
            .Buttons(
                X.Button()
                    .ID("Button1")
                    .Text("Save")
                    .Icon(Icon.Disk)
                    .DirectEvents(de =>
                        {
                            de.Click.Method = HttpMethod.POST;
                            de.Click.Url = Url.Action("Save");
                            de.Click.Success = "saveHandler('EditWindow','PanelList')";
                        }),
                X.Button()
                    .Text("Cancle")
                    .Icon(Icon.Cancel) 
                    .Handler("parent.Ext.getCmp('EditWindow').close()")
            )
        )
    controller:
     public ActionResult Save(Sys_Organization entity)
            {
                ServiceFactory.Instance.Get<Sys_OrganizationService>(Sys_Organization).Save(entity);
                return this.Direct();
            }
    I try like this :
    1、 X.DropDownFieldFor(model => model.ParentId,true)
    .Text(Model.ParentOrg.FullName)
    In the entity,I can't get the "ParentId" value

    2、 X.DropDownFieldFor(model => model.ParentOrg.FullName,true)
    In the entity,I can't get the "ParentId" value ,but I can get "ParentOrg.FullName" value


    I want to get the "ParentId" value in code behind,and show "ParentOrg.FullName" text in dropdownlist.
    How could I do?
    Last edited by Dalen; Aug 25, 2014 at 5:42 AM.
  2. #2
    Hi @Dalen,

    Welcome to the Ext.NET forums!

    I think you might need to implement a ModelBinder. Here is some information about that.
    http://forums.ext.net/showthread.php...l=1#post105622
  3. #3

    another way to solve it

    Thank you @Daniil
    The example you provided make me confused,I try like that but it doesn't work.
    I have another way to solve it
    I put a hiddenvalue and bind it to "ParentId", the dropdownlist is still bind "ParentOrg.FullName"
    when I click the treepanel's item and set the value to it,just like this:
     X.HiddenFor(model=>model.ParentId).ID("hideParentID"),
    X.DropDownFieldFor(model => model.ParentOrg.FullName,true)
     . ....
      .Listeners(l => {
          l.ItemClick.Handler = @"getValues(this,record);";
      })
     function getValues(_this,record)
            {
                var Id = Ext.getCmp("hideParentID");
                _this.dropDownField.setValue(record.data.id, record.data.text, true);
                Id.setValue(record.data.id);
            }
    If it can bind smartly in the code behind,it will be better..

Similar Threads

  1. [CLOSED] how to set Column 's id and text from dropdownlist
    By hdsoso in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: May 21, 2013, 10:46 AM
  2. Replies: 0
    Last Post: Oct 05, 2012, 2:53 PM
  3. [CLOSED] Multicombo always show the same text
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 28, 2012, 9:23 AM
  4. Can't show a static text-string ...
    By andersgunnare in forum 1.x Help
    Replies: 0
    Last Post: Jun 09, 2011, 8:49 AM
  5. Replies: 2
    Last Post: Mar 04, 2010, 7:12 PM

Tags for this Thread

Posting Permissions