PDA

View Full Version : [CLOSED] Linked ComboBox/SelectBox help needed.



tnwheeler
Jul 24, 2013, 5:19 AM
I have a series of 3 ComboBoxes (actually SelectBoxes) that are populated by SQLDatasources (call them Quarters, Employees, and Projects)

The first box (Quarters) is the driver for the second (Employees).
The third (Projects) requires the selection from the first and second to populate.
Only when all three are selected can the main controls on the pages be executed.

I cannot find any examples of how to set this up (using SQLDatasources -- My queries are part of a framework for selecting the data). I had something working for 1.x but this have gone squirrely in the conversion to 2.x and now I can get the ComboBoxes populated on page load and the defaults selected but when a different Quarter or Employee is picked the second and third boxes do not reload. It is as though the reload event never get off the page.

I can't really post my code as it is tied to a database backend and it is a little to complex. If someone need to look at it to give me some assistance PM me and I will see about getting you a copy.

Regards,

Nathan Wheeler

Daniil
Jul 24, 2013, 6:54 AM
Hi @tnwheeler,

We can try to create a prototype basing on one of these examples.
http://examples2.ext.net/#/Form/ComboBox/Linked_ComboBoxes/
http://examples2.ext.net/#/Form/ComboBox/Ajax_Linked_Combos/

What example is closer to your requirement?

tnwheeler
Jul 24, 2013, 3:20 PM
Daniil,

I am not sure what the significant difference is between the two examples you listed -- other than the obvious fact that one uses a proxy/webservice and the other uses a direct read of the XML file to load the City data. Given that my situation where all three components get their data from separate SQLDatasources I would guess either would work (unless I am missing a fundamental piece of the puzzle).

I would rather not have to create a plethora of support files for this control but if the webservice route is the way to go then I will do so.

Additional elements to consider are:
The first ComboBox is dynamic based on the user.
The second ComboBox will usually only have 1 item (the current user) and only in the case of a supervisor will it have more that the single item.
If the selected value of the first changes both the second and the third ComboBoxes will need to be updated (but their selected values may not need to change).

Regards,

Baidaly
Jul 25, 2013, 3:13 AM
Hello!

Sorry, we don't quite understand what is your problem? Is it in combination of Combox and SQLDatasources or in loading linked Comboxes?

Also, is it possible to provide a sample without Database or with MockObjects?

Daniil
Jul 25, 2013, 6:20 AM
Yes, we should start with a simple prototype without SQL/database stuff. If all the ComboBoxes' Stores loads its data via, I guess, AjaxProxies in your real application, then we could use PageProxies in our prototype. Just for the sake of ease.

So, can you post some simple basic sample which would demonstrate the scenario and the point where you are actually stuck?

tnwheeler
Jul 25, 2013, 6:54 PM
I have tried to simply the control I am building but since the problem is that the stores of the comboboxes are not rebinding to the SQLDatasources it is impossible for me to recreate without the database component.

If you would like me to send you the files for the control privately as I currently have it I can.

Thanks,

Baidaly
Jul 26, 2013, 3:49 AM
Can you create a sample using our databases from Examples? We can use them to investigate your problem.

tnwheeler
Jul 26, 2013, 2:10 PM
Can you create a sample using our databases from Examples? We can use them to investigate your problem.

I will see what I can do. I assume you are using the standard northwind sample database?

I tried sending you and Daniil a PM yesterday with what i have put together but was stopped by the character limit on PM's... :0

Regards,

Daniil
Jul 26, 2013, 4:44 PM
Please avoid PMs. We are trying to keep public as much as possible.


I have tried to simply the control I am building but since the problem is that the stores of the comboboxes are not rebinding to the SQLDatasources it is impossible for me to recreate without the database component.


What about to replace the database with some dummy data?

tnwheeler
Jul 26, 2013, 11:04 PM
What about to replace the database with some dummy data?
How do you propose I do that? I am binding my ext:stores to an asp:SqlDatasource. I guess I can switch to a different model if I have to but I was really hoping for a solution that did not relay on the complexity of maintaining multiple web services for each combobox.

Baidaly
Jul 26, 2013, 11:41 PM
I will see what I can do. I assume you are using the standard northwind sample database?

I tried sending you and Daniil a PM yesterday with what i have put together but was stopped by the character limit on PM's... :0

Regards,

Yes, we can use Northwind to check your issue. You can use pastebin.com to post your sample.

Daniil
Jul 29, 2013, 6:08 AM
How do you propose I do that? I am binding my ext:stores to an asp:SqlDatasource. I guess I can switch to a different model if I have to but I was really hoping for a solution that did not relay on the complexity of maintaining multiple web services for each combobox.

Yes, there definitely should be solution with SqlDataSources. Ok, if you are be able to create a test case with the Northwind database, it would be good. Also you can consider a possibility to use asp:ObjectDataSource instead of asp:SqlDataSource for creating a test case.

tnwheeler
Jul 31, 2013, 12:27 AM
I have spent way too many hours trying to adapt my code to fit a data schema that you might be able to execute but I cannot find a reasonable example that is comparable to what I need to do.
What I am looking for is some direction on how to link three (or more) comboboxes together so that each is dependant on the other and then wrap it in a control that i can drop on a page and use it to drive a final GridPanel.

As suggested by Baidaly I am attaching a copy of my code (as i have it) via pastebin.

SelectionToolbar.ascx: http://pastebin.com/FbxenW0B
SelectionToolbar.ascx.cs: http://pastebin.com/9nk8UNh7

I am fully aware that you will not be able to execute the code but I am hoping that someone can give me a idea of what I should really be doing. :)

If I have to scrap this code and start again I will, but I have fast approaching deadline and cannot afford to do that without good reason.

Thanks again,

Daniil
Jul 31, 2013, 6:37 AM
I created the following example from scratch with ObjectDataSources.

Hope it will be helpful.

Page

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

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

<script runat="server">
protected void ComboBox1_Select(object sender, DirectEventArgs e)
{
this.ComboBox2.GetStore().DataBind();
}

protected void ComboBox2_Select(object sender, DirectEventArgs e)
{
this.ComboBox3.GetStore().DataBind();
}
</script>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<asp:ObjectDataSource
ID="ObjectDataSource1"
runat="server"
SelectMethod="GetAll"
TypeName="ObjectDataSourceForComboBox1" />

<ext:ComboBox
ID="ComboBox1"
runat="server"
DisplayField="text"
ValueField="value">
<Store>
<ext:Store
runat="server"
DataSourceID="ObjectDataSource1">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<DirectEvents>
<Select OnEvent="ComboBox1_Select" />
</DirectEvents>
</ext:ComboBox>

<asp:ObjectDataSource
ID="ObjectDataSource2"
runat="server"
SelectMethod="GetAll"
TypeName="ObjectDataSourceForComboBox2">
<SelectParameters>
<asp:ControlParameter Name="parentComboBoxValue" ControlID="ComboBox1" PropertyName="Value" />
</SelectParameters>
</asp:ObjectDataSource>


<ext:ComboBox
ID="ComboBox2"
runat="server"
DisplayField="text"
ValueField="value">
<Store>
<ext:Store
runat="server"
DataSourceID="ObjectDataSource2">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<DirectEvents>
<Select OnEvent="ComboBox2_Select" />
</DirectEvents>
</ext:ComboBox>

<asp:ObjectDataSource
ID="ObjectDataSource3"
runat="server"
SelectMethod="GetAll"
TypeName="ObjectDataSourceForComboBox3">
<SelectParameters>
<asp:ControlParameter Name="parentComboBoxValue" ControlID="ComboBox2" PropertyName="Value" />
</SelectParameters>
</asp:ObjectDataSource>


<ext:ComboBox
ID="ComboBox3"
runat="server"
DisplayField="text"
ValueField="value">
<Store>
<ext:Store
runat="server"
DataSourceID="ObjectDataSource3">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</form>
</body>
</html>


ObjectDataSourceForComboBox1.cs

using System;

public class ObjectDataSourceForComboBox1
{
public static object[] GetAll()
{
return new object[]
{
new
{
value = "1",
text = "text1_" + DateTime.Now.Second
},
new
{
value = "2",
text = "text2_" + DateTime.Now.Second
},
new
{
value = "3",
text = "text3_" + DateTime.Now.Second
}
};
}
}

ObjectDataSourceForComboBox2.cs

using System;

public class ObjectDataSourceForComboBox2
{
public static object[] GetAll(string parentComboBoxValue)
{
return new object[]
{
new
{
value = parentComboBoxValue + "_1",
text = parentComboBoxValue + "_text1_" + DateTime.Now.Second
},
new
{
value = parentComboBoxValue + "_2",
text = parentComboBoxValue + "_text2_" + DateTime.Now.Second
},
new
{
value = parentComboBoxValue + "_3",
text = parentComboBoxValue + "_text3_" + DateTime.Now.Second
}
};
}
}

ObjectDataSourceForComboBox3.cs

using System;

public class ObjectDataSourceForComboBox3
{
public static object[] GetAll(string parentComboBoxValue)
{
return new object[]
{
new
{
value = parentComboBoxValue + "_1",
text = parentComboBoxValue + "_text1_" + DateTime.Now.Second
},
new
{
value = parentComboBoxValue + "_2",
text = parentComboBoxValue + "_text2_" + DateTime.Now.Second
},
new
{
value = parentComboBoxValue + "_3",
text = parentComboBoxValue + "_text3_" + DateTime.Now.Second
}
};
}
}

tnwheeler
Jul 31, 2013, 11:14 PM
Daniil,

Your example has been a help to get past my mental roadblock. I have converted to use SQLDataSources and believe I see where I overengineered my solution back when I started working with Coolite/Ext.net 1.x.

Thanks,