Apr 14, 2009, 12:33 PM
Combobox used in a grid display object[object] when edited for first time
Hello,
I have created an application which contains the grid containing combobox in one of it's columns. I want to bind the class as a dataindex to this column.
I am able to bind the class to column with combobox editor , however it doesn't work when u edit column for first time as it displays the [object]object text in combpbox.
Please help..
Below is the code.
I have created an application which contains the grid containing combobox in one of it's columns. I want to bind the class as a dataindex to this column.
I am able to bind the class to column with combobox editor , however it doesn't work when u edit column for first time as it displays the [object]object text in combpbox.
Please help..
Below is the code.
<%@ Import Namespace="System.Collections.Generic" %><%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e){
FldCollection objFldColl;
RecItemCollection objRecItemColl;
RecItem objRecItem;
objFldColl = new FldCollection();
objRecItemColl = new RecItemCollection();
Fld objFld;
objFld = new Fld();
objFld.ID = 111;
objFld.Name = "111 Fld";
objFld.RID = 1;
objFldColl.Add(objFld);
objFld = new Fld();
objFld.ID = 222;
objFld.Name = "222 Fld";
objFld.RID = 1;
objFldColl.Add(objFld);
objFld = new Fld();
objFld.ID = 333;
objFld.Name = "333 Fld";
objFld.RID = 2;
objFldColl.Add(objFld);
objFld = new Fld();
objFld.ID = 444;
objFld.Name = "444 Fld";
objFld.RID = 2;
objFldColl.Add(objFld);
objFld = new Fld();
objFld.ID = 555;
objFld.Name = "555 Fld";
objFld.RID = 2;
objFldColl.Add(objFld);
objRecItem = new RecItem();
objRecItem.ID = 1;
objRecItem.Comments = "Comments for Item 1";
objRecItem.Field1 = objFldColl[1];
objRecItemColl.Add(objRecItem);
objRecItem = new RecItem();
objRecItem.ID = 2;
objRecItem.Comments = "Comments for Item 2";
objRecItem.Field1 = objFldColl[2];
objRecItemColl.Add(objRecItem);
storeGrid.DataSource = objRecItemColl;
storeGrid.DataBind();
storeCombo.DataSource = objFldColl;
storeCombo.DataBind();
}
[Serializable]
public class Rec{
public Rec(){
//// TODO: Add constructor logic here//
}
private int m_ID;
private string m_Description = string.Empty;
private RecItemCollection m_items;
public int ID
{get { return m_ID; }
set { m_ID = value; }
}
public string Description{
get { return m_Description; }
set { m_Description = value; }
}
public RecItemCollection Items{
get { return m_items; }
set { m_items = value; }}
}
[Serializable]
public class RecItem{
public RecItem()
{// TODO: Add constructor logic here}
private int m_ID;
private String m_Comment;
private Fld m_Field1;
public int ID
{get { return m_ID; }
set { m_ID = value; }
}
public String Comments
{
get { return m_Comment; }
set { m_Comment = value; }
}
public Fld Field1
{
get { return m_Field1; }
set { m_Field1 = value; }}}
public class RecItemCollection : List<RecItem>
{public RecItemCollection() { }
}
[Serializable]public class Fld
{public Fld(){}
private int m_ID;
private int m_RID;
private string m_Name = string.Empty;
public int ID
{get { return m_ID; }
set { m_ID = value; }
}
public int RID
{get { return m_RID; }
set { m_RID = value; }
}
public string Name
{get { return m_Name; }
set { m_Name = value; }
}
}
public class FldCollection : List<Fld>
{
public FldCollection() { }}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title></title>
<script type="text/javascript">
var renderField = function(value) {
if (Ext.isEmpty(value)) {
return "";}
if (! Ext.isEmpty(value.Name)) {
return value.Name; //if Value contains a class
}
var r = storeCombo.getById(value); //if value contains a valuefield
if (! Ext.isEmpty(r)) {
return r.data.Name;
}
return "";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server"></ext:ScriptManager>
<ext:Store ID="storeGrid" runat="server" SerializationMode="Complex">
<Reader>
<ext:JsonReader ReaderID="ID">
<Fields>
<ext:RecordField Name="ID" Type="Int" ></ext:RecordField>
<ext:RecordField Name="Comments"></ext:RecordField>
<ext:RecordField Name="Field1"></ext:RecordField>
</Fields></ext:JsonReader></Reader>
</ext:Store>
<ext:Store ID="storeCombo" runat="server">
<Reader>
<ext:JsonReader ReaderID="ID">
<Fields>
<ext:RecordField Name="ID"></ext:RecordField>
<ext:RecordField Name="Name"></ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
<ext:GridPanel ID="GridPanel1" EnableViewState="true" runat="server" StoreID="storeGrid" Height="500" Width="600">
<ColumnModel runat="server">
<Columns>
<ext:Column Header="RecItemId" dataIndex="ID" Width="50"></ext:Column>
<ext:Column Header="Comments" DataIndex="Comments" Width="150">
<Editor>
<ext:TextField runat="server" ></ext:TextField>
</Editor>
</ext:Column>
<ext:Column DataIndex="Field1" Header="Field" >
<Renderer Fn="renderField" />
<Editor>
<ext:ComboBox ID="ComboBox1" runat="server" StoreID="storeCombo" DisplayField="Name" ValueField="ID" ForceSelection="true" TriggerAction="All">
</ext:ComboBox>
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" SingleSelect="false" runat="server" />
</SelectionModel>
</ext:GridPanel>
</form>
</body>
</html>