|
 |
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|

May 25th, 2009, 12:42 PM
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 25
Thanks: 3
Thanked 1 Time in 1 Post
|
|
Cascading dropdowns bound to MSSQL
I have seen several threads on this issue and can not seem to get any of it to work for me. I have two drop downs on a form that cascade down for data entry. Basically they are a 'Long Term Goal', and then a 'Short Term Goal' based on the first drop down. I keep getting this error every time I try to bind the data to the SQL file.
When I try to databind the second dropdown, I get this error 'Databinding methods such as Eval(), XPath(), and Bind() can only be used in the ......'
I have tried turning the 'EnableView State' on and off with no luck.
Here are my dropdown codes:
Code:
<InsertItemTemplate>
<asp:DropDownListID="DropDownList2"runat="server"AutoPostBack="True"DataSourceID="LT"DataTextField="LTGoal"DataValueField="LTGoalID"EnableViewState="False">
</asp:DropDownList>
<asp:SqlDataSourceID="LT"runat="server"ConnectionString="<%$ ConnectionStrings:anthemprodConnectionString %>"SelectCommand="SELECT [LTGoalID], [LTGoal] FROM [TblGoalsLT]">
</asp:SqlDataSource>
STGoal:
<asp:SqlDataSourceID="ST"runat="server"ConnectionString="<%$ ConnectionStrings:anthemprodConnectionString %>"SelectCommand="SELECT SpecTargetID, SpecificTarget, MeasureID FROM TblGoalsST WHERE (MeasureID = @SpecTargetID)">
<SelectParameters>
<asp:ControlParameterControlID="DropDownList2"Name="SpecTargetID"PropertyName="SelectedValue"Type="Int32"/>
</SelectParameters>
</asp:SqlDataSource>
<asp:DropDownListID="DropDownList1"runat="server"DataSourceID="ST"DataTextField="SpecificTarget"DataValueField="SpecTargetID">
</asp:DropDownList>
<br/>
<asp:LinkButtonID="InsertButton"runat="server"CausesValidation="True"CommandName="Insert"Text="Insert"/>
<asp:LinkButtonID="InsertCancelButton"runat="server"CausesValidation="False"CommandName="Cancel"Text="Cancel"/>
</InsertItemTemplate>
Is there some C# code bihind I am not understanding, or is there something in the dropdown setup that I am missing?
Any help would be GREATLY appreicated!
|

May 25th, 2009, 05:24 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
Have you considered using the CascadindDropDown AJAX control? This would be easier, in addition to avoiding the postback to populate the second list.
http://www.asp.net/AJAX/AjaxControlT...gDropDown.aspx
|

July 24th, 2010, 01:41 AM
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 25
Thanks: 3
Thanked 1 Time in 1 Post
|
|
Still having problems
I actualle gave up on this for a while, but still want to get this done. I am trying to incorporate the AJAX control but having problems..
Here is the code I have:
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"/>
<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>
I have been able to get the dropdowns to display correctly, but when I try to bind the second dropdown, I still get that databinding error. Am I not setting something up right with the AJAX control?
|

August 6th, 2010, 06:18 AM
|
Registered User
|
|
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thank
thanks for sharing nice information
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |