PDA

View Full Version : [CLOSED] How to pre select a value in ComboBox inside ComponentColumn



Fahd
Oct 26, 2015, 10:11 PM
Hello,
I am trying to pre-select a value in the cmbAdjustmentTypes combobox during Page_Load but it is not working. For example, Employee 1 is suppose to have AdjustmentType 1 pre selected but it is not.

Please see screenshot for reference.24301

Below is my code:


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

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="Newtonsoft.Json" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest || !IsPostBack)
{
this.Store1.DataSource = new object[]
{
new object[] { "Employee 1", 1,3 },
new object[] { "Employee 2", 2,3 },
new object[] { "Employee 3", 2,3 },
new object[] { "Employee 4", 2,3},
new object[] { "Employee 5", 2,3 },
new object[] { "Employee 6",8,3},
new object[] { "Employee 7", 8,3 },
new object[] { "Employee 8", 8,3},
new object[] { "Employee 9", 9,3}
};

this.Store1.DataBind();

stAdjustmentTypes.DataSource = GetAdjustmentTypes();
stAdjustmentTypes.DataBind();
}

}



public List<AdjustmentType> GetAdjustmentTypes()
{
List<AdjustmentType> adj = new List<AdjustmentType>(3);

for (int j = 0; j < 10; j++)
{
adj.Add(new AdjustmentType("Adjustment Type " + j, j));
}

return adj;
}



public class AdjustmentType
{
public AdjustmentType(string name, int adjustmentTypeID)
{
AdjustmentName = name;
AdjustmentTypeID = adjustmentTypeID;
}

public string AdjustmentName { get; set; }
public int AdjustmentTypeID { get; set; }
}


</script>
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>ComponentColumn Over Editor - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />

<style>
.x-over-editor-grid tr.x-grid-row
{
height: 22px;
}
</style>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<h1>
ComponentColumn multi controls</h1>
<ext:GridPanel ID="GridPanel1" runat="server" Title="Setup Adjustments" Width="1200"
Height="300">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="EmployeeName" Type="String" />
<ext:ModelField Name="AdjustmentTypeID" Type="Int" />
<ext:ModelField Name="RouteID" Type="Int" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column1" runat="server" DataIndex="EmployeeName" Text="Adjustment Type">
</ext:Column>
<ext:ComponentColumn ID="ComponentColumn2" runat="server" Editor="true" Text="Adjustment"
Width="600">
<Component>
<ext:Container runat="server">
<Items>
<ext:ComboBox ID="cmbAdjustmentTypes" runat="server" DataIndex="AdjustmentTypeID" ValueField="AdjustmentTypeID" DisplayField="AdjustmentName" EmptyText="Select Adjustment">
<Store>
<ext:Store ID="stAdjustmentTypes" runat="server" IsPagingStore="false" AutoLoad="false">
<Model>
<ext:Model ID="mdAjustmentType" runat="server">
<Fields>
<ext:ModelField Name="AjustmentTypeID" />
<ext:ModelField Name="AdjustmentName" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>

</ext:ComboBox>
<ext:ComboBox ID="ComboBox2" runat="server" DataIndex="RouteID" EmptyText="Select Route">
<Items>
<ext:ListItem Text="Item 1" Value="1" Mode="Raw" />
<ext:ListItem Text="Item 2" Value="2" Mode="Raw" />
<ext:ListItem Text="Item 3" Value="3" Mode="Raw" />
<ext:ListItem Text="Item 4" Value="4" Mode="Raw" />
<ext:ListItem Text="Item 5" Value="5" Mode="Raw" />
<ext:ListItem Text="Item 6" Value="6" Mode="Raw" />
<ext:ListItem Text="Item 7" Value="7" Mode="Raw" />
<ext:ListItem Text="Item 8" Value="8" Mode="Raw" />
<ext:ListItem Text="Item 9" Value="9" Mode="Raw" />
</Items>
</ext:ComboBox>
</Items>
</ext:Container>
</Component>
</ext:ComponentColumn>
</Columns>
</ColumnModel>
</ext:GridPanel>

</form>
</body>
</html>

Daniil
Oct 27, 2015, 2:58 PM
Hi @Fahd,

A ComponentColumn's Editor="true" is not going to work with a Container. It expects a field in a ComponentColumn's Component.

With your setup you have to manage applying of initial values manually. It could be done inside a ComponentColumn's BeforeBind listener.

An easier solution would be splitting the ComboBoxes into individual ComponentColumns.

Fahd
Oct 27, 2015, 3:55 PM
Thanks for your reply. Can you please provide an example on how to do this in the ComponentColumn's BeforeBind listener?

geoffrey.mcgill
Oct 27, 2015, 8:10 PM
Can you please provide an example on how to do this in the ComponentColumn's BeforeBind listener?

Can you give the tips Danill provided a try first? If your sample works, please share here with the community as it may help others in the future with a similar requirement.

If you cannot get your sample to work, please simplify that sample down to the minimum required to reproduce, and post an update.

Fahd
Oct 28, 2015, 8:23 PM
I will find an alternative solution. Thanks anyway for your help. You may close this thread.