2012-01-23 41 views
1

コンボボックスフィールドをグリッドパネルに追加する必要があります。私はコンボボックスを追加しましたが、元の選択を表示していません。ドロップダウンをクリックすると、すべてのドロップダウン値が正しく取得され、フィールドの値を選択できます。初期選択されたプロブレン。私はext.netを初めて使い、何かが正しい順序で行われていないことを疑っています。ext.netコンボボックスに初期値が表示されない

おかげで、

ジェニー

これは、分離コード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"を選択すると、最初に選択された値が正しく表示されます

関連する問題