PDA

View Full Version : [CLOSED] ComboBox default selected value



nikisbeta
Jul 27, 2012, 3:31 PM

Daniil
Jul 27, 2012, 5:22 PM
Hi,

Please replace:

this.cmbOrganizacniJednotkyChange.Value = "778"
this.cmbOrganizacniJednotkyChange.Text = "Display text for 778"


with


/* C# */
this.cmbOrganizacniJednotkyChange.SelectedItems.Ad d(new Ext.Net.ListItem() { Value = "778" });

nikisbeta
Jul 30, 2012, 2:03 PM
Thanks, but still does't work :-(

Daniil
Jul 30, 2012, 2:15 PM
Please clarify what Ext.NET sources do you use?

Do you bind numbers or strings into the Id ModelField?

<ext:ModelField Name="Id" />

Could you post a response of ZemeHledej.ashx?

nikisbeta
Jul 30, 2012, 2:46 PM
Hi
ID is number,
I make sample project whit this problem.
http://www.dno.cz/WebSite1.zip

Daniil
Jul 30, 2012, 2:52 PM
Then please set up Raw mode for the ListItem

new Ext.Net.ListItem() { Value = "778", Mode = ParameterMode.Raw }

nikisbeta
Jul 30, 2012, 2:54 PM
Bingo !
Thank you.

nikisbeta
Jul 30, 2012, 3:38 PM
I was happy when it worked.
But this works only in non paged listing. (sorry, but was not in the example)

For example:
Total records = 100,
First page:

{total:100,'items':[ {'Id':10,'Nazev':'xxxx1'},{'Id':11,'Nazev':'xxxx2' },{'Id':12,'Nazev':'xxxx3'},{'Id':13,'Nazev':'xxxx 4'}] }


Second page:

{total:100,'items':[ {'Id':14,'Nazev':'xxxx4'},{'Id':15,'Nazev':'xxxx5' },{'Id':16,'Nazev':'xxxx6'},{'Id':17,'Nazev':'xxxx 7'}] }

If I select field from first page, its OK:

this.ComboBox1.SelectedItems.Add(new Ext.Net.ListItem() { Value = "10", Mode = Ext.Net.ParameterMode.Raw });

but, I select field from second (and others) page its wrong:

this.ComboBox1.SelectedItems.Add(new Ext.Net.ListItem() { Value = "14", Mode = Ext.Net.ParameterMode.Raw });

This sample is here:
http://www.dno.cz/WebSite1.v2.zip (www.dno.cz/WebSite1.v2.zip)



<ext:Store ID="Store1" runat="server" AutoLoad="true">
<Proxy>
<ext:AjaxProxy Url="Handler.ashx">
<ActionMethods Read="POST">
</ActionMethods>
<Reader>
<ext:JsonReader Root="items" TotalProperty="total">
</ext:JsonReader>
</Reader>
</ext:AjaxProxy>
</Proxy>

<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="Id" Type="Int" />
<ext:ModelField Name="Nazev" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>

<ext:ComboBox ID="ComboBox1" ColSpan="5" runat="server"
StoreID="Store1" DisplayField="Nazev" ValueField="Id" QueryMode="Remote" AutoSelect="true" PageSize="4">
<ListConfig LoadingText="Searching..." MinWidth="300" Border="true"></ListConfig>
<Listeners>

</Listeners>
</ext:ComboBox>



Test handler code:


if (context.Request.Params["page"] != null && int.Parse(context.Request.Params["page"]) > 1)
{
context.Response.Write("{total:100,'items':[ {'Id':14,'Nazev':'xxxx4'},{'Id':15,'Nazev':'xxxx5' },{'Id':16,'Nazev':'xxxx6'},{'Id':17,'Nazev':'xxxx 7'}] }");
}
else
{
context.Response.Write("{total:100,'items':[ {'Id':10,'Nazev':'xxxx1'},{'Id':11,'Nazev':'xxxx2' },{'Id':12,'Nazev':'xxxx3'},{'Id':13,'Nazev':'xxxx 4'}] }");
}

Daniil
Jul 30, 2012, 7:06 PM
But this works only in non paged listing.

Yes, ComboBox can select some item only if a record assigned with that item is loaded into the ComboBox Store.

So, if a record of that item is not loaded, even if you set up an item text, there, actually, won't be a selected item. The same is in Ext.NET v1.

If it suites your needs, I can suggest to leave just

this.cmbOrganizacniJednotkyChange.Text = "Display text for 778"

removing

this.cmbOrganizacniJednotkyChange.Value = "778"
because the last causes an attempt to find a respective record. If not found, then no selected item.

nikisbeta
Jul 31, 2012, 8:32 AM
Thanks,
this code display text in ComboBox:


this.ComboBox1.Text = "Display text for 778";
but, i need set value for ComboBox.
In version 1.x a used this code:


this.cmbOrganizacniJednotkyChange.Value = "778"
this.cmbOrganizacniJednotkyChange.Text = "Display text for 778"
this.cmbOrganizacniJednotkyChange.ValueNotFoundTex t = "Display text for 778"

In this version value "778" is not set. Value is text ("Display text for 778")
Please, there is a solution to display the text "Display text for 778" and store the value "778"

Maybe this is my problem :-(
http://www.sencha.com/forum/showthread.php?138434-Setting-the-editable-combobox-to-a-value-that-is-not-in-the-list-results-in-empty-val


thank you

Daniil
Jul 31, 2012, 10:29 AM
In version 1.x a used this code:


this.cmbOrganizacniJednotkyChange.Value = "778"
this.cmbOrganizacniJednotkyChange.Text = "Display text for 778"
this.cmbOrganizacniJednotkyChange.ValueNotFoundTex t = "Display text for 778"


Well, this code is a hack in Ext.NET v1, not supported behavior. Please note that setting up the Text property doesn't affect, i.e. if you'd leave

this.cmbOrganizacniJednotkyChange.Value = "778"
this.cmbOrganizacniJednotkyChange.Text = "Display text for 778"
you will see "778" in the ComboBox.

So, really, you see the ValueNotFoundText in the ComboBox. Repeat myself, it's a hack.

As I mentioned before, an item should be loaded to get it correctly working.

Here is a related discussion.
http://forums.ext.net/showthread.php?19864

Ganeshpatil
Oct 25, 2012, 10:48 AM
suppse my selebox id is ddlcountry then
ddlcountry.selectedItem.value its not work
is any other solution for that please tell m.

Daniil
Oct 25, 2012, 2:20 PM
Hi @Ganeshpatil,


ddlcountry.selectedItem.value its not work

Please provide a sample to reproduce.

Ganeshpatil
Oct 25, 2012, 2:38 PM
StateMasterProp objStateMasterProp = new StateMasterProp();
StateMasterBAL objStateMasterBAL = new StateMasterBAL();
objStateMasterProp = objStateMasterBAL.GetStateMasterData("State_Id= '" + Request.QueryString["p2"].ToString() + "' ");

if (objStateMasterProp != null)
{
strStateId = objStateMasterProp.State_Id;
txtState_Name.Text = objStateMasterProp.State_Name;
txtState_Desc.Text = objStateMasterProp.State_Desc;
ddlCountry.ValueField=objStateMasterProp.Country_I d;
}

here i used this code for edit mode in wich i want to assign the value to the country seletbox wich is came in property of statemasterprop.
how to assign that value to that ddlcountry seletbox please tell me... suppose country id is 3 then that particular country should be select
in the selectbox........
hope u understand my problem........

Daniil
Oct 25, 2012, 4:07 PM
Please clarify where do you apply a value for the ComboBox?

Also this code looks wrong.

ddlCountry.ValueField=objStateMasterProp.Country_I d;

The ValueField must be an ModelField's Name.

Ganeshpatil
Oct 26, 2012, 7:15 AM
In asp.net we can assign the particular value to the dropdownlist is as follow

dropdownlist.selectedvalue=6;

in this case dropdownlist select the item whose value is 6.
In the same way i want to assign the value to the extnet selectbox control..
Hope now u understand........

Daniil
Oct 26, 2012, 7:55 AM
Please use a ComboBox's SelectedItem and a SelectedIndex properties.

Ganeshpatil
Oct 26, 2012, 10:07 AM
Why we can not use selectbox for that purpose ..........?

Daniil
Oct 26, 2012, 10:39 AM
You can. SelectBox has the same properties.

Just I thought we are talking about ComboBox since the thread's title starts with "ComboBox".

prashanth.bussa
Oct 26, 2012, 11:15 AM
Hi all please suggest me to implement the autopopulate multi (comma seperated) selection text box using ext.net

Daniil
Oct 26, 2012, 11:21 AM
Hi @prashanth.bussa,

Please start a new forum thread.

prashanth.bussa
Oct 26, 2012, 11:33 AM
Hi Im new to this blog plz let me know how to start a new forum thread

Daniil
Oct 26, 2012, 11:36 AM
Welcome to the Ext.NET forums!

Please clarify what Ext.NET version do you use?

prashanth.bussa
Oct 26, 2012, 12:05 PM
Welcome to the Ext.NET forums!

Please clarify what Ext.NET version do you use?

Hi Danill im using 1.0

Daniil
Oct 26, 2012, 12:17 PM
This forum:
http://forums.ext.net/forumdisplay.php?4-1-x-Help

A green "+ Post New Thread" button at the top on the left.

Ganeshpatil
Oct 26, 2012, 12:58 PM
im using the same property but its not assiging the value to combox ...

combox1.selecteditem.value=5;

this code im using but not work............

Daniil
Oct 26, 2012, 1:22 PM
Please try:

ComboBox1.SelectedItem.Value = "5";

A string instead of an integer.

Ganeshpatil
Oct 27, 2012, 12:48 PM
but still that was not work..
i used the following statement insted of that it sets the value to combobox1 but i want to select the text related to that value

Combobox1.SetValue("4");

please tell me how to do that......

by

Ganesh...

Daniil
Oct 29, 2012, 11:26 AM
Please provide a sample to reproduce.