Advertisement

03.27.2008 at 06:50PM PDT, ID: 23276243
[x]
Attachment Details

how cascade dependent dropdown bind gridview

Asked by bianchef in Visual Studio .NET 2005, Microsoft Visual C#.Net, WebApplications

I need two cascading dependent dropdowns for the user to select a ShipName then a ShipRegion from a gridview to return several fields in the Northwind database.

The attached code snippet gets the list for ShipName and ShipRegion but selecting a item from each does not return the gridview with only those selections. Instead, I get all the items in all the selections. No error is returned either.

Otherwise, the gridview is working well as the user scrolls through all the items. This solution is urgent.

My environment is ASP.NET 2.0, C#, SQL Server 2000Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
aspx page
...
<div style="margin-top: 12px;">
		Select Category:
		<asp:dropdownlist id="ddlCategories" runat="server" appenddatabounditems="True" autopostback="True"
			datasourceid="itCategories" datatextfield="ShipName" datavaluefield="OrderID">
		</asp:dropdownlist>
		<asp:sqldatasource id="itCategories" runat="server" connectionstring="<%$ ConnectionStrings:Northwind.SQL %>"
			selectcommand="SELECT [OrderID], [ShipName] FROM [Orders] ORDER By [ShipName]">
		</asp:sqldatasource>
	</div> 
 
<div>
		Select Product:
		<asp:dropdownlist id="ddlProducts" runat="server" appenddatabounditems="True" autopostback="True"
			datasourceid="itProducts" datatextfield="ShipRegion" datavaluefield="OrderID">
		</asp:dropdownlist>
		<asp:sqldatasource id="itProducts" runat="server" connectionstring="<%$ ConnectionStrings:Northwind.SQL %>"
			selectcommand="SELECT [OrderID], [ShipRegion] FROM [Orders] ORDER BY [ShipRegion]">
		</asp:sqldatasource>
	</div>			
<asp:Panel ID="pnlGridView" runat="server" Width="100%">
...
                </asp:GridView>
                <asp:sqldatasource id="itProducts1" runat="server" connectionstring="<%$ ConnectionStrings:Northwind.SQL %>"
		selectcommand="SELECT [OrderID], [ShipRegion], [ShipName] 
FROM [Orders] 
WHERE [OrderID] =  @OrderID ORDER BY [ShipName]">
		<selectparameters>
			<asp:controlparameter controlid="ddlProducts" name="OrderID" propertyname="SelectedValue" type="Int32" />
			<asp:controlparameter controlid="ddlCategories" name="OrderID" propertyname="SelectedValue" type="Int32" />
		</selectparameters>
	</asp:sqldatasource>
 
 
aspx.cs page
...
private string GetGridViewRowDropDownListValue(GridViewRow row, string sControlName)
        {
            string sFieldValue = string.Empty;
 
            DropDownList _ctl = (DropDownList)row.FindControl(sControlName);
            if (_ctl == null)
            {
                throw new Exception("GetGridViewRowDropDownListValue: could not find " + sControlName + " control!");
            }
 
            sFieldValue = _ctl.SelectedValue;
            return sFieldValue;
        }
...
        private string GetDropDownListFieldValue(string sControlName)
        {
            string sFieldValue = string.Empty;
 
            DropDownList _ctl = (DropDownList)fvOrders.FindControl(sControlName);
            if (_ctl == null)
            {
                throw new Exception("GetDropDownListFieldValue: could not find " + sControlName + " control!");
            }
 
            sFieldValue = _ctl.SelectedValue;
            return sFieldValue;
        }
[+][-]03.28.2008 at 07:19AM PDT, ID: 21230593

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.28.2008 at 08:41AM PDT, ID: 21231377

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.28.2008 at 08:53AM PDT, ID: 21231500

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Studio .NET 2005, Microsoft Visual C#.Net, WebApplications
Sign Up Now!
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628