Combo box display only blank list

515 views Asked by At

I am using Ext.net 3.0. I have a combo box and created store in it to get multiple values from server side. It's getting 5 value from server side, but it display only blank list.

enter image description here

Coding for combo box..............

   <ext:ComboBox runat="server" ListWidth="350" ID="Branches" FieldLabel="Branch" DisplayField="Name" ValueField="Number" AllowBlank="false">
                        <Store>
                            <ext:Store runat="server">
                                <Reader>
                                    <ext:JsonReader IDProperty="Number">
                                        <Fields>
                                            <ext:RecordField Name="Number"></ext:RecordField>
                                            <ext:RecordField Name="Name"></ext:RecordField>
                                        </Fields>
                                    </ext:JsonReader>
                                </Reader>
                            </ext:Store>
                        </Store>
</ext:ComboBox>

Server side coding.......

  var branchList = from b in Branches select new { Number = b.Number, Name =   b.Name };

  List<object> listBranchToAdd = new List<object>();
  foreach (var a in branchList)
   {
     listBranchToAdd.Add(a);
   }

  Branches.Store.Primary.DataSource = listBranchToAdd;
  Branches.Store.Primary.DataBind();

My Research -

  1. Someone said that, don't add a combo in store directly, create a store separately by given store id and then use store id in combo, but it doesn't work.

  2. var branchList returning value.. I have checked it. When i use cmbBranches.setValue(listBranchToAdd[0]); then it display value in Fiddler. but doesn't display in combo box properly.

3.Just give a storeId in store and use in server side for binding data in store instead of binding in combobox. I have tried it but it doesn't work.

2

There are 2 answers

0
Puneet Chawla On BEST ANSWER

Finally, I got a solution of this question. I didn't properly understand the actual logic why it's working but it works proper.

Previous Code - It was not working

var branchList = from b in Branches select new { Number = b.Number, Name =   b.Name };

  List<object> listBranchToAdd = new List<object>();
  foreach (var a in branchList)
   {
     listBranchToAdd.Add(a);
   }

  Branches.Store.Primary.DataSource = listBranchToAdd;
  Branches.Store.Primary.DataBind();

New Code - It is working

var branchList = from b in Branches select b;

      List<Branch> listBranchToAdd = new List<Branch>();
      foreach (var a in branchList)
       {
         listBranchToAdd.Add(a);
       }

      Branches.Store.Primary.DataSource = listBranchToAdd;
      Branches.Store.Primary.DataBind();
3
sakir On

take a look at this example

<ext:ComboBox runat="server" ID="cmb" EmptyText="select.." ForceSelection="true" AllowBlank="false"
Editable="false" Icon="BulletTick" Flex="1" ValueField="Id" DisplayField="Name" FieldLabel="Name">
        <Store>
         <ext:Store ID="strcmb" runat="server">
              <Model>
                  <ext:Model ID="Model4" runat="server">
                     <Fields>
                      <ext:ModelField Name="Number" />
                      <ext:ModelField Name="Name" />
                     </Fields>
                  </ext:Model>
              </Model>
         </ext:Store>
    </Store>
</ext:ComboBox>

and server side

 strcmb.DataSource = _bll.Get();
 strcmb.DataBind();

in yor case you dont need to <Reader><ext:JsonReader...> this part if dont make a web service request

update

    var branchList = from b in Branches select new MyClass { Number = b.Number, Name =   b.Name };

strcmb.DataSource = branchList.ToList();
  strcmb.DataBind();
        MyClass{
        public string Name {get;set;}
        public int Number {get ;set;}
        }