Мне нужно добавить поля со списком в сетку.Я добавил поля со списком, но они не показывают исходный выбор.Когда я нажимаю на раскрывающийся список, я правильно получаю все раскрывающиеся значения и могу выбрать значение для поля.Проблема с первоначальным выбором.Я новичок в 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>