 |
| Visual Web Developer 2008 Discuss creating ASP.NET 3.5 sites with Microsoft's Visual Web Developer 2008. If your question is more specific to a piece of code than the Visual tool, see the ASP.NET 3.5 forums instead. If your question is specific to the "Express Edition" be sure to state that in your post. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Web Developer 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 31st, 2009, 02:58 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 25
Thanks: 3
Thanked 1 Time in 1 Post
|
|
Dual Drop Down Issues
Hi Guys, hoping for a little guidance here.
I have a mssql data entry form that has some drop down selectors. I am able to base one selector on the previous selecion as so:
Code:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ProductionID"
DataSourceID="test" DefaultMode="Insert">
<InsertItemTemplate>
LTGoal:
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
DataSourceID="lt" DataTextField="LTGoal" DataValueField="LTGoalID"
SelectedValue='<%# Bind("LTGoal") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="lt" runat="server"
ConnectionString="<%$ ConnectionStrings:anthemprodConnectionString %>"
SelectCommand="SELECT [LTGoalID], [LTGoal] FROM [TblGoalsLT]">
</asp:SqlDataSource>
<br />
STGoal:
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="st"
DataTextField="SpecificTarget" DataValueField="SpecTargetID"
AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="st" runat="server"
ConnectionString="<%$ ConnectionStrings:anthemprodConnectionString %>"
SelectCommand="SELECT TblGoalsST.SpecTargetID, TblGoalsST.SpecificTarget, TblGoalsST.MeasureID, TblGoalsLT.LTGoalID FROM TblGoalsST LEFT OUTER JOIN TblGoalsLT ON TblGoalsST.MeasureID = TblGoalsLT.LTGoalID WHERE (TblGoalsLT.LTGoalID = @MeasureID)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList2" Name="MeasureID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
</asp:FormView>
This appears to work fine visually, but every time I try to databind the second dropdown (STGOAL) I get an error message. Is there something I am totally missing here?
|
|

January 31st, 2009, 10:29 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Hello.
Can you please say what's your error??
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

February 1st, 2009, 12:20 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 25
Thanks: 3
Thanked 1 Time in 1 Post
|
|
Not quite sure
If I databind the frist dropdown and not the second, everything works fine. The problem is that second dropdown is not bound to anything so the data is not getting stored in my database.
When I databind both dropdown menus so both fields are stored in the db, I get an error. When I make selection from item 1 and it autoposts back I get this error 'Server Error in '/' Application.'
Any thoughts?
|
|

February 2nd, 2009, 08:16 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
HI there...
That's the standard error, it always named that way ;).
Could you be so kind of turning off custom error so you receive a very large explain of what is happening??
Thanks...
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

February 2nd, 2009, 12:18 PM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 25
Thanks: 3
Thanked 1 Time in 1 Post
|
|
Heres the full error
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Source Error:
[No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET Files\root\13002084\d6fb212d\App_Web_dnejiesb.0.cs Line: 0
Stack Trace:
[InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.] System.Web.UI.Page.GetDataItem() +2049122 ASP.anthem_interface_addtasktest_aspx.__DataBindin g__control11(Object sender, EventArgs e) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET Files\root\13002084\d6fb212d\App_Web_dnejiesb.0.cs :0 System.Web.UI.Control.OnDataBinding(EventArgs e) +99 System.Web.UI.WebControls.ListControl.OnDataBindin g(EventArgs e) +11 System.Web.UI.WebControls.ListControl.PerformSelec t() +31 System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +70 System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +82 System.Web.UI.WebControls.ListControl.OnPreRender( EventArgs e) +26 System.Web.UI.Control.PreRenderRecursiveInternal() +86 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Control.PreRenderRecursiveInternal() +170 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
|
|

February 4th, 2009, 01:14 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
I hope that this can help clear things up for you.
Code:
Sub getAreaID(ByVal FacID As Integer, ByVal RuleID As Integer)
Dim SQL As String = "SELECT Areas.AreaID, Areas.AreaName FROM Areas INNER JOIN Facilities ON Areas.FacID = Facilities.FacID WHERE Facilities.FacID = " & FacID & " AND Areas.AreaName = 'Wells 1148.1' ORDER BY Len(Areas.AreaName), Areas.AreaName ;"
Dim oDA As New SqlDataAdapter(SQL, _oConn)
Dim oDS As New DataSet
oDA.Fill(oDS)
ddlAreaID.DataSource = oDS
ddlAreaID.DataTextField = "AreaName"
ddlAreaID.DataValueField = "AreaID"
ddlAreaID.DataBind()
ddlAreaID.Items.Insert(0, New ListItem("All", 0))
btnAdd.Visible = False
End Sub
Private Sub ddlAreaID_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlAreaID.SelectedIndexChanged
grdInventory.Visible = False
tbrLegend.Visible = False
ddlSubID.Items.Clear()
getSubID(ddlAreaID.SelectedValue, _RuleID)
End Sub
Sub getSubID(ByVal AreaID As Integer, ByVal RuleID As Integer)
Dim SQL As String = "SELECT Subareas.SubID, Subareas.SubName FROM Subareas INNER JOIN Areas ON Subareas.AreaID = Areas.AreaID WHERE Areas.AreaID = " & AreaID & " ORDER BY Subareas.SubName ASC;"
Dim oDA As New SqlDataAdapter(SQL, _oConn)
Dim oDS As New DataSet
oDA.Fill(oDS)
ddlSubID.DataSource = oDS
ddlSubID.DataTextField = "SubName"
ddlSubID.DataValueField = "SubID"
ddlSubID.DataBind()
ddlSubID.Items.Insert(0, New ListItem("All", 0))
btnAdd.Visible = False
If oDS.Tables(0).Rows.Count = 1 Then
ddlSubID.SelectedIndex = 1
End If
End Sub
|
|

February 7th, 2009, 03:07 AM
|
|
Authorized User
|
|
Join Date: Jan 2009
Posts: 25
Thanks: 3
Thanked 1 Time in 1 Post
|
|
Thanks
So I assume this is going into my codebehind file?
Would I sub in my LTGoals for 'AREA' and my STGoals for 'SUB"?
|
|
 |