PDA

View Full Version : [CLOSED] ComboBox load value



FpNetWorth
Dec 21, 2012, 1:49 PM
Hi all,

I want to know what is the best way to load the combo from code behind in v.2 .
In fact, in v.1, I use the following code:


this.comboBoxCompanies.Value = employee.getCompanyId;
where employee.getCompanyId is an integer.

In v.2 , I use the following code:


this.comboBoxCompanies.SelectedItems.Add(new Ext.Net.ListItem { Value = "" + employee.getCompanyId });
this.comboBoxCompanies.UpdateSelectedItems();


The two previous code work good, but I'm wonder if there is a way in v.2 to load data in the same way as in v.1

Best Regards

Daniil
Dec 21, 2012, 3:29 PM
Hi @FpNetWorth,

Setting .Value in Ext.NET v1 just selects an item, it doesn't load anything.

It should causes the same effect in Ext.NET v2.

The requirement is unclear.

Please provide a working sample for Ext.NET v1. I will try to convert it for Ext.NET v2.

RCN
Dec 21, 2012, 3:31 PM
I would like to list another ways to accomplish it:

By Index

comboBoxCompanies.Select(1);

By Value

comboBoxCompanies.Select("1");

By Value

comboBoxCompanies.SetValue("1");

By Value

comboBoxCompanies.SetValueAndFireSelect("1");



Setting .Value in Ext.NET v1 just selects an item, it doesn't load anything.

I agree with you Daniil, but i think that he meant select instead of load. Is that correct @FpNetWorth?

Daniil
Dec 21, 2012, 3:37 PM
Probably, you are right, Raphael.

By setting up a ComboBox's Value property appears to be working.

Example

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

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

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.ComboBox1.GetStore();
store.DataSource = new object[]
{
new object[] { 1, "Item 1" },
new object[] { 2, "Item 2" },
new object[] { 3, "Item 3" }
};
store.DataBind();
}
}

protected void Select(object sender, DirectEventArgs e)
{
this.ComboBox1.Value = 1;
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:ComboBox
ID="ComboBox1"
runat="server"
DisplayField="text"
ValueField="value">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" Type="Int" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
<ext:Button runat="server" Text="Select" OnDirectClick="Select" />
</form>
</body>
</html>

FpNetWorth
Dec 24, 2012, 10:37 AM
I agree with you Daniil, but i think that he meant select instead of load. Is that correct @FpNetWorth?

Thank you @RCN.
Yes, this is what I meant.
Thank you for the clarification.

FpNetWorth
Dec 24, 2012, 10:49 AM
Hi Daniil,

Thank you for the sample that you provided.

The problem that I face is that I can't get the value of the selected Item.

When we click the button "Get", we have the following scenarios:
1- If the user click "Get" without selecting any value from the combo, we get the selected text instead of the value.
2- If the user select the same item that was selected on the load, we get the selected text instead of the value.
3- If the user select a different item than the selected item on load, we get the true value of the selected item.

Please find below the code:


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

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

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.ComboBox1.GetStore();
store.DataSource = new object[]
{
new object[] { 1, "Item 1" },
new object[] { 2, "Item 2" },
new object[] { 3, "Item 3" }
};
store.DataBind();
this.ComboBox1.Value = 2;
}
}

protected void Select(object sender, DirectEventArgs e)
{
this.ComboBox1.Value = 1;
}
protected void GetValue(object sender, DirectEventArgs e)
{
object comboValue = this.ComboBox1.Value;
string comboVal = this.ComboBox1.SelectedItem.Value;
object a = ComboBox1.SelectedItems[0].Value;

}

</script>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:ComboBox
ID="ComboBox1"
runat="server"
DisplayField="text"
ValueField="value">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="value" Type="Int" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:Store>
</Store>
</ext:ComboBox>
<ext:Button ID="Button1" runat="server" Text="Select" OnDirectClick="Select" />
<ext:Button ID="Button2" runat="server" Text="Get" OnDirectClick="GetValue" />
</form>
</body>
</html>


Regards.

Daniil
Dec 24, 2012, 12:50 PM
It looks to be a bug. We are investigating.

Thank you.

Daniil
Dec 25, 2012, 10:25 AM
It has been fixed in SVN.

Thank you for the report.

FpNetWorth
Dec 27, 2012, 9:54 AM
It looks to be a bug. We are investigating.

Thank you.


Thank you Daniil..