2012-01-23 4 views
1

Мне нужно добавить поля combobox в сетку. Я добавил комбинированные поля, но они не показывают оригинальный выбор. Когда я нажимаю на раскрывающийся список, я получаю все значения выпадающего списка и могу выбрать значение для поля. Проблема с первоначальным выбором. Я новичок в ext.net, и я подозреваю, что что-то не сделано в правильном порядке.extnet combo box не отображает начальное значение

Спасибо,

Jenny

Это является CodeBehind EditExample.aspx.cs:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using DataTypes; 
using Ext.Net; 

namespace myApp 
{ 
    public class info 
    { 
     public string Name { get; set; } 
     public string Code { get; set; } 
     public Description aDescription { get; set; } 

     public int DescriptionId 
     { 
      get { return this.aDescription != null ? this.aDescription.id : -1; } 
     } 

     public static List<info> GetAll() 
     { 
      return new List<info> 
      { 
       new info { Code = "1", aDescription = Description.GetAt(1), Name = "" }, 
       new info { Code = "2", aDescription = Description.GetAt(2), Name = "2 Names" }, 
       new info { Code = "3", aDescription = Description.GetAt(3), Name = "3 Names" }, 
       new info { Code = "4", aDescription = Description.GetAt(4), Name = "4 Names" }, 
       new info { Code = "5", aDescription = Description.GetAt(5), Name = "5 Names" }, 
       new info { Code = "6", aDescription = Description.GetAt(6), Name = "6 Names" } 
      }; 
     } 
    } 

    public class Description 
    { 
     public int id {get; set; } 
     public string description { get; set; } 

     public static Description GetAt(int Index) 
     { 
      return new Description { description = "Description: " + Index, id = Index }; 
     } 

     public static List<Description> GetAll(int max) 
     { 
      List<Description> all = new List<Description>(); 
      for (int i = 1; i <= max; i++) 
      { 
       Description thisDesc = new Description { description = "Description: " + i, id = i }; 
       all.Add(thisDesc); 
      }; 
      return all; 
     } 
    } 

    public partial class EditExample : System.Web.UI.Page 
    { 
     public List<info> thisInfo = new List<info>(); 
     public List<Description> thisCombo = new List<Description>(); 

     protected void Page_Load(object sender, EventArgs e) 
     { 
      thisCombo = Description.GetAll(5); 
      thisInfo = info.GetAll(); 

      this.extStore.DataSource = thisInfo; 

      this.extStoreCombo.DataSource = thisCombo; 
      this.extStoreCombo.DataBind(); this.extStore.DataBind(); 

     } 
    } 

Это ExitExample.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditExample.aspx.cs" Inherits="myApp.EditExample" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <script type="text/javascript"> 

     var onBeforeEdit = function (e) { 
      var column = e.grid.getColumnModel().columns[e.column], 
      ed = column.getCellEditor(e.row); 
      if (ed && (e.value != '' && e.value != undefined)) { 
       return false; 
      } 
     } 

     var descriptionRenderer = function (id) { 
      var r = extStoreCombo.getById(id); 

      if (Ext.isEmpty(r)) { 
       return ""; 
      } 

      return r.data.description; 
     }; 


     </script> 

</head> 
<body> 
    <form id="form1" runat="server"> 

    <ext:ResourceManager runat="server" /> 
    <ext:Store ID="extStore" runat="server" > 
      <Reader> 
       <ext:JsonReader> 
        <Fields> 
         <ext:RecordField Name = "Name" /> 
         <ext:RecordField Name = "Code" ></ext:RecordField> 
         <ext:RecordField Name = "DescriptionId" ></ext:RecordField> 
        </Fields> 
       </ext:JsonReader> 
      </Reader> 
     </ext:Store> 
    <div> 
    <ext:GridPanel ID="extGrd" runat="server" StripeRows="true" TrackMouseOver="true" 
    StoreID="extStore" Cls="x-grid-custom" 
    Height="250px" Layout="fit"> 
    <ColumnModel ID="cmFC" runat="server"> 
     <Columns> 
      <ext:Column ColumnID="Name" DataIndex="Name" Header="Name"> 
      <Editor> 
       <ext:TextField ID = "TextField2" runat = "server"/> 
      </Editor> 
      </ext:Column> 
      <ext:Column ColumnID="Code" DataIndex="Code" Header="Code"> 
      </ext:Column> 
      <ext:Column ColumnID="DescriptionId" DataIndex="DescriptionId" Header="Description" Editable ="true" > 
       <Renderer fn="descriptionRenderer" /> 
       <Editor> 
        <ext:ComboBox ID="cbDescription" runat="server" Mode="Remote" LazyRender="true" 
        TriggerAction="All" DisplayField ="description" ValueField = "id" Editable="false" ForceSelection="true"> 
        <Store> 
         <ext:Store ID="extStoreCombo" runat="server"> 
         <Reader> 
          <ext:JsonReader IDProperty="id"> 
          <Fields> 
           <ext:RecordField Name="id" /> 
           <ext:RecordField Name="description" /> 
          </Fields> 
          </ext:JsonReader> 
         </Reader> 
         </ext:Store> 
        </Store> 
         <%--<Listeners> 
          <Select Fn="onSelect" /> 
         </Listeners>--%> 
        </ext:ComboBox> 
       </Editor> 
      </ext:Column> 
      <ext:CheckColumn ColumnID="Check" DataIndex = "Check" Header = "Check" Editable = "true"> 
      </ext:CheckColumn> 
     </Columns> 
    </ColumnModel> 
    <Listeners> 
     <BeforeEdit Fn="onBeforeEdit" /> 
<%--  <CellClick Fn="setEditor2" /> --%> 
     <Render Handler="this.getColumnModel().setEditable(3, true);" /> 
    </Listeners> 
    <SelectionModel> 
     <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" MoveEditorOnEnter="true"/> 
    </SelectionModel> 
    <LoadMask ShowMask="true" /> 
    </ext:GridPanel> 
    </div> 
    <div> 
    <ext:Button ID="btnSubmitHH" runat="server" Text="Submit Household" Icon="Accept" Disabled="true"> 
     <DirectEvents> 
      <Click OnEvent="SubmitHH"> 
       <Confirmation ConfirmRequest="true" Message="Are you sure you want to submit?" /> 
      </Click> 
     </DirectEvents> 
    </ext:Button> 
    </div> 
    </form> 
</body> 
</html> 

ответ

2

я провел некоторое время очистки и, как показано ниже, функция работает правильно. Я думаю, что важным изменением было перемещение конфигурации <ext:Store> из ComboBox. ComboBox Store нужно настроить только один раз на странице, где-то выше.

Пример

<%@ Page Language="C#" %> 

<%@ Import Namespace="System.Collections.Generic" %> 

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> 

<script runat="server"> 
    public List<info> thisInfo = new List<info>(); 
    public List<Description> thisCombo = new List<Description>(); 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     thisCombo = Description.GetAll(5); 
     thisInfo = info.GetAll(); 

     this.Store1.DataSource = thisInfo; 
     this.Store1.DataBind(); 

     this.Store2.DataSource = thisCombo; 
     this.Store2.DataBind(); 
    } 

    public class info 
    { 
     public string Name { get; set; } 
     public string Code { get; set; } 
     public Description aDescription { get; set; } 

     public int DescriptionId 
     { 
      get { return this.aDescription != null ? this.aDescription.id : -1; } 
     } 

     public static List<info> GetAll() 
     { 
      return new List<info> 
      { 
       new info { Code = "1", aDescription = Description.GetAt(1), Name = "" }, 
       new info { Code = "2", aDescription = Description.GetAt(2), Name = "2 Names" }, 
       new info { Code = "3", aDescription = Description.GetAt(3), Name = "3 Names" }, 
       new info { Code = "4", aDescription = Description.GetAt(4), Name = "4 Names" }, 
       new info { Code = "5", aDescription = Description.GetAt(5), Name = "5 Names" }, 
       new info { Code = "6", aDescription = Description.GetAt(6), Name = "6 Names" } 
      }; 
     } 
    } 

    public class Description 
    { 
     public int id { get; set; } 
     public string description { get; set; } 

     public static Description GetAt(int Index) 
     { 
      return new Description 
      { 
       description = "Description: " + Index, 
       id = Index 
      }; 
     } 

     public static List<Description> GetAll(int max) 
     { 
      List<Description> all = new List<Description>(); 

      for (int i = 1; i <= max; i++) 
      { 
       Description thisDesc = new Description 
       { 
        description = "Description: " + i, 
        id = i 
       }; 

       all.Add(thisDesc); 
      }; 

      return all; 
     } 
    } 
</script> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html> 
<head runat="server"> 
    <title>Ext.NET Example</title> 
    <script type="text/javascript"> 
     var descriptionRenderer = function (id) { 
      var r = Store2.getById(id); 

      return Ext.isEmpty(r) ? "" : r.data.description; 
     }; 
</script> 
</head> 
<body> 
<form runat="server"> 
    <ext:ResourceManager runat="server" /> 

    <ext:GridPanel runat="server" Height="250"> 
     <Store> 
      <ext:Store ID="Store1" runat="server" > 
       <Reader> 
        <ext:JsonReader> 
         <Fields> 
          <ext:RecordField Name="Name" /> 
          <ext:RecordField Name="Code" /> 
          <ext:RecordField Name="DescriptionId" /> 
         </Fields> 
        </ext:JsonReader> 
       </Reader> 
      </ext:Store> 
     </Store> 
     <Bin> 
      <ext:Store ID="Store2" runat="server"> 
       <Reader> 
        <ext:JsonReader IDProperty="id"> 
         <Fields> 
          <ext:RecordField Name="id" /> 
          <ext:RecordField Name="description" /> 
         </Fields> 
        </ext:JsonReader> 
       </Reader> 
      </ext:Store> 
     </Bin> 
     <ColumnModel runat="server"> 
      <Columns> 
       <ext:Column ColumnID="Name" DataIndex="Name" Header="Name"> 
        <Editor> 
         <ext:TextField runat = "server"/> 
        </Editor> 
       </ext:Column> 
       <ext:Column ColumnID="Code" DataIndex="Code" Header="Code" /> 
       <ext:Column 
        ColumnID="DescriptionId" 
        DataIndex="DescriptionId" 
        Header="Description" 
        Editable="true"> 
        <Renderer fn="descriptionRenderer" /> 
        <Editor> 
         <ext:ComboBox 
          runat="server" 
          DisplayField ="description" 
          ValueField = "id" 
          Editable="false" 
          ForceSelection="true" 
          StoreID="Store2" 
          /> 
        </Editor> 
       </ext:Column> 
      </Columns> 
     </ColumnModel> 
    </ext:GridPanel> 
</form> 
</body> 
</html> 

Надеется, что это помогает.

+0

Вам не нужно, чтобы переместить магазин из выпадающего списка. Он отлично работает в поле со списком, по крайней мере, в версии 2.2. –

1

Просто удалить Mode = «Remote», чтобы показать начальное значение selectyed правильно