PDA

View Full Version : [CLOSED] Simple select Dynamic Combo



CarWise
Mar 09, 2015, 11:57 AM
Doing something wrong. Not sure what. Want to select the item with the 90720 value.



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

<script runat="server">

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
createKeuzeLijst().AddTo(fpTest);
preselectValue();
}
}

public ComboBox createKeuzeLijst()
{
const int nVeldID = 1;
const string cVeldNaam = "TestField";
const string cVeldOmschrijving = "TestDescription";
ComboBox cb = new ComboBox
{
ID = string.Format("cb{0}", cVeldNaam),
ToolTip = cVeldOmschrijving,
FieldLabel = cVeldNaam,
ValueField = "cItemWaarde",
DisplayField = "cItemText",
AnchorHorizontal = "100%",
EmptyText = "-- maak keuze --"
};

AddItems(cb, nVeldID);
return cb;
}

public void AddItems(ComboBox cb, Int32 nVeldId)
{
Dictionary<String, String> dic = new Dictionary<string, string>();
dic.Add("99999", "99999 - Ford Rent actie auto");
dic.Add("90720", "90720 - Ford Rent ondersteuning");
dic.Add("90750", "90750 - Incentive ondersteuning");
foreach (KeyValuePair<string, string> entry in dic)
{
cb.Items.Add(new Ext.Net.ListItem(entry.Key, entry.Value));
}
}

public void preselectValue()
{
ComboBox cb = X.GetCmp<ComboBox>("cbTestField");
cb.SelectedItems.Add(new Ext.Net.ListItem { Value = "90720", Mode = ParameterMode.Raw });
cb.UpdateSelectedItems();
}

</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Dynamic combo</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:FormPanel runat="server" ID="fpTest" />
</form>
</body>
</html>

Daniil
Mar 09, 2015, 12:35 PM
Hi Martin,

It appears I can select the item with the 90720 without any problem. Could you, please, clarify what is happening for you?

CarWise
Mar 09, 2015, 12:56 PM
Hi Daniil,

So this code is working for you ? I just see no selected items in my combo. (combo is filled, but no item selected)

What I mean is that the item must be preselected with this code. But it is not.

Will update from SVN and try again. I probably use older set.

Martin

Daniil
Mar 09, 2015, 1:05 PM
So this code is working for you ?

Yes, it is definitely working for me. The item gets selected.


Will update from SVN and try again. I probably use older set.

Yes, please. Please also try in different browsers. As for IE, please ensure the compatibility node is switched off.

CarWise
Mar 09, 2015, 2:52 PM
Updated SVN

Tried in several browsers, but I don't get a selected item.

The dropdown is populated with the right items.

I don't have a clue why the same code it's working on your side.. and not on mine..

Martin

CarWise
Mar 09, 2015, 2:54 PM
Generated HTML






<!DOCTYPE html>







<html>



<head>



<link type="text/css" rel="stylesheet" href="/extjs/resources/ext_theme_gray/ext-theme-gray-all-debug-embedded-css/ext.axd?v=27984 (http://localhost:63059/extjs/resources/ext_theme_gray/ext-theme-gray-all-debug-embedded-css/ext.axd?v=27984)" id="ext-theme" />



<link type="text/css" rel="stylesheet" href="/extnet/resources/css/extnet-all-debug-embedded-css/ext.axd?v=27984 (http://localhost:63059/extnet/resources/css/extnet-all-debug-embedded-css/ext.axd?v=27984)" id="extnet-styles" />



<script type="text/javascript" src="/extjs/ext-all-dev-js/ext.axd?v=27984 (http://localhost:63059/extjs/ext-all-dev-js/ext.axd?v=27984)"></script>



<script type="text/javascript" src="/extnet/extnet-all-debug-js/ext.axd?v=27984 (http://localhost:63059/extnet/extnet-all-debug-js/ext.axd?v=27984)"></script>



<script type="text/javascript" src="/extnet/locale/ext-lang-nl-js/ext.axd?v=27984 (http://localhost:63059/extnet/locale/ext-lang-nl-js/ext.axd?v=27984)"></script>



<title>



Dynamic combo



</title>



<script type="text/javascript">



//<![CDATA[



Ext.net.ResourceMgr.init({



id: "ctl03",



aspForm: "ctl01",



theme: "gray"



});Ext.onReady(function(){Ext.create("Ext.form.Panel",{



id: "fpTest",



renderTo: "App.fpTest_Container",



url: unescape("%2ftest%2f"),



waitMsgTarget: ""



});Ext.net.ResourceMgr.destroyCmp("App.cbTestField");App.fpTest.add({



id: "cbTestField",



xtype: "combobox",



anchor: "100%",



fieldLabel: "TestField",



emptyText: "-- maak keuze --",



displayField: "cItemText",



queryMode: "local",



valueField: "cItemWaarde",



store: [["99999 - Ford Rent actie auto","99999"],["90720 - Ford Rent ondersteuning","90720"],["90750 - Incentive ondersteuning","90750"]]



});App.cbTestField.setSelectedItems([{value:90720}]);});



//]]>



</script>



</head>



<body>



<form method="post" action="" id="ctl01">



<div class="aspNetHidden">



<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />



<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />



<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTIwNzE2MjQ0ODdkGAEFHl9fQ29udHJvbHNSZXF1aXJ lUG9zdEJhY2tLZXlfXxYCBQVjdGwwMwUGZnBUZXN0gA6wzzxyV orTu4wCy9zJJwu7HmGr1zqn6QEFoUTvg+Q=" />



</div>







<script type="text/javascript">



//<![CDATA[



var theForm = document.forms['ctl01'];



if (!theForm) {



theForm = document.ctl01;



}



function __doPostBack(eventTarget, eventArgument) {



if (!theForm.onsubmit || (theForm.onsubmit() != false)) {



theForm.__EVENTTARGET.value = eventTarget;



theForm.__EVENTARGUMENT.value = eventArgument;



theForm.submit();



}



}



//]]>



</script>















<div id="App.fpTest_Container"></div>







<div class="aspNetHidden">







<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="80F1723F" />



<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAIPXqjgT5U+KToa7OFaOdVXNpGzZOwh9RDF3/tMV5ai8yPXVunfitbkn/Ijagi9VVSykaR6iGkAdK7X9BgbQgfY" />



</div></form>







<!-- Visual Studio Browser Link -->



<script type="application/json" id="__browserLink_initializationData">



{"appName":"Chrome","requestId":"9a9297fdad9046ccb64b9b051ac10be6"}



</script>



<script type="text/javascript" src="http://localhost:52111/6409619fc7194289b70221880ec7ad40/browserLink" async="async"></script>



<!-- End Browser Link -->







</body>



</html>

Daniil
Mar 10, 2015, 7:15 AM
Sorry, I misunderstood the issue.

Ok, there is a few changes that should be applied.

1. .AddTo(), .UpdateSelectedItems(), X.GetCmp<> are supposed to be used only during DirectEvetns or DirectMethods.

2. ParameterMode.Value should be used here:

cb.SelectedItems.Add(new Ext.Net.ListItem { Value = "90720", Mode = ParameterMode.Raw });

3. Also you should switch Key and Value here:

cb.Items.Add(new Ext.Net.ListItem(entry.Key, entry.Value));

This appears to be working.

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
var cb = createKeuzeLijst();
preselectValue(cb);
fpTest.Items.Add(cb);
}
}

public ComboBox createKeuzeLijst()
{
const int nVeldID = 1;
const string cVeldNaam = "TestField";
const string cVeldOmschrijving = "TestDescription";
ComboBox cb = new ComboBox
{
ID = string.Format("cb{0}", cVeldNaam),
ToolTip = cVeldOmschrijving,
FieldLabel = cVeldNaam,
ValueField = "cItemWaarde",
DisplayField = "cItemText",
AnchorHorizontal = "100%",
EmptyText = "-- maak keuze --"
};

AddItems(cb, nVeldID);
return cb;
}

public void AddItems(ComboBox cb, Int32 nVeldId)
{
Dictionary<String, String> dic = new Dictionary<string, string>();
dic.Add("99999", "99999 - Ford Rent actie auto");
dic.Add("90720", "90720 - Ford Rent ondersteuning");
dic.Add("90750", "90750 - Incentive ondersteuning");
foreach (KeyValuePair<string, string> entry in dic)
{
cb.Items.Add(new Ext.Net.ListItem(entry.Value, entry.Key));
}
}

public void preselectValue(ComboBox cb)
{
cb.SelectedItems.Add(new Ext.Net.ListItem { Value = "90720", Mode = ParameterMode.Value });
}

CarWise
Mar 10, 2015, 8:57 AM
Thx Daniil. Still learning :)