View Single Post
  #1 (permalink)  
Old July 24th, 2010, 01:33 AM
mashype mashype is offline
Authorized User
 
Join Date: Jan 2009
Posts: 25
Thanks: 3
Thanked 1 Time in 1 Post
Default Cascading Drop Downs for a novice

I have trying to get this to work right forever and have had absolutely no luck. I am trying to setup a two tier dropdown menu for long terms goals to narrow selections of a second list of short term goals. I am able to get the dropdowns to work based on two tables from my MSSQL database, but when I try to insert the record I get that awful error....

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

I have researched and researched, but every solution I find is too complex to figure out for this novice programmer. Can anyone show me a simple solution or walk me through how I setup the whole webservice stuff???

Here is my page file:

Code:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Index.aspx.cs"Inherits="Anthem_Admin_Index" %>
<%@Registerassembly="AjaxControlToolkit"namespace="AjaxControlToolkit"tagprefix="asp" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ScriptManagerID="ScriptManager1"runat="server"/>
<asp:FormViewID="FormView1"runat="server"DataKeyNames="ProductionID"DataSourceID="Tasks"EnableModelValidation="True"DefaultMode="Insert">
<InsertItemTemplate>
LTGoal:
<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"DataSourceID="LT"DataTextField="LTGoal"DataValueField="LTGoalID">
</asp:DropDownList>
<br/>
STGoal:
<asp:DropDownListID="DropDownList2"runat="server"DataSourceID="ST"DataTextField="SpecificTarget"DataValueField="SpecTargetID"SelectedValue='<%# Bind("STGoal") %>'>
</asp:DropDownList>
<asp:CascadingDropDownID="DropDownList2_CascadingDropDown"runat="server"Enabled="True"ServiceMethod="GetDropDownContents"TargetControlID="DropDownList2"UseContextKey="True"Category="Tasks"EmptyText="Select LT Goal">
</asp:CascadingDropDown>
<br/>
Comments:
<asp:TextBoxID="CommentsTextBox"runat="server"Text='<%# Bind("Comments") %>'/>
<br/>
<asp:LinkButtonID="InsertButton"runat="server"CausesValidation="True"CommandName="Insert"Text="Insert"/>
&nbsp;<asp:LinkButtonID="InsertCancelButton"runat="server"CausesValidation="False"CommandName="Cancel"Text="Cancel"/>
<asp:SqlDataSourceID="LT"runat="server"ConnectionString="<%$ ConnectionStrings:anthemprodConnectionString %>"SelectCommand="SELECT [LTGoalID], [LTGoal] FROM [TblGoalsLT]">
</asp:SqlDataSource>
<asp:SqlDataSourceID="ST"runat="server"ConnectionString="<%$ ConnectionStrings:anthemprodConnectionString %>"SelectCommand="SELECT [SpecTargetID], [SpecificTarget] FROM [TblGoalsST] WHERE ([MeasureID] = @MeasureID)">
<SelectParameters>
<asp:ControlParameterControlID="DropDownList1"Name="MeasureID"PropertyName="SelectedValue"Type="Int32"/>
</SelectParameters>
</asp:SqlDataSource>
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSourceID="Tasks"runat="server"ConnectionString="<%$ ConnectionStrings:anthemprodConnectionString %>"DeleteCommand="DELETE FROM [TblProduction] WHERE [ProductionID] = @ProductionID"InsertCommand="INSERT INTO [TblProduction] ([LTGoal], [STGoal], [Comments]) VALUES (@LTGoal, @STGoal, @Comments)"SelectCommand="SELECT [ProductionID], [LTGoal], [STGoal], [Comments] FROM [TblProduction]"UpdateCommand="UPDATE [TblProduction] SET [LTGoal] = @LTGoal, [STGoal] = @STGoal, [Comments] = @Comments WHERE [ProductionID] = @ProductionID">
<DeleteParameters>
<asp:ParameterName="ProductionID"Type="Int32"/>
</DeleteParameters>
<InsertParameters>
<asp:ParameterName="LTGoal"Type="Int32"/>
<asp:ParameterName="STGoal"Type="Int32"/>
<asp:ParameterName="Comments"Type="String"/>
</InsertParameters>
<UpdateParameters>
<asp:ParameterName="LTGoal"Type="Int32"/>
<asp:ParameterName="STGoal"Type="Int32"/>
<asp:ParameterName="Comments"Type="String"/>
<asp:ParameterName="ProductionID"Type="Int32"/>
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
And my code....
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
publicpartialclassAnthem_Admin_Index : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
publicstatic AjaxControlToolkit.CascadingDropDownNameValue[] GetDropDownContents(string knownCategoryValues, string category)
{
returndefault(AjaxControlToolkit.CascadingDropDownNameValue[]);
}
}



I know it cant be all that complicated, but I can not seem to figure it out on my own.

Please help......