[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

ASP.NET Formview control dropdownlist SelectedIndexChanged problem

Asked by DeMyu in Programming for ASP.NET

Tags: ASP.NET, VB, Formview

I have problems getting the Formview control with two dependent dropdownlists to work in Edit Mode. I have say dropdownlist A and dropdownlist B where Dropdownlist B is dependent on dropdownlist A.

My goal is such that when a user clicks the edit button in the Formview the selectedvalues of dropdownlist A and dropdownlist B should be the values obtained from the database.

Here is the error message that I am receiving from the web server when I click edit to put the formview into edit mode.

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.

The error disappears when I remove SelectedValue='<%# Bind("appID") %>'  from

<asp:DropDownList ID="dropApplication" runat="server" DataTextField="appName" DataValueField="appID" SelectedValue='<%# Bind("appID") %>' />

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:
65:
66:
67:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="romID">
							<EditItemTemplate>
								<table class="tblborder">
 <tr>
										<td class="formlabel"><LABEL class="reqlabel" for="dropComponent">Component:</LABEL><span class="form-required">*</span></td>
										<td align="left">	
									<asp:DropDownList ID="dropComponent" runat="server" DataSourceID="SqlDataSource01" DataTextField="orgName" DataValueField="orgID" AppendDataBoundItems="true" AutoPostBack="True" SelectedValue='<%# Bind("orgID") %>' OnSelectedIndexChanged="dropComponent_SelectedIndexChanged">
                                    <asp:ListItem Value="">
                                            -- Choose a component --
                                        </asp:ListItem>
		                           </asp:DropDownList>
		                           </td>
		                           <td><asp:RequiredFieldValidator runat="server" Display="Dynamic" ControlToValidate="dropComponent" ErrorMessage="<img src='images/common/required_trans.gif' align='absmiddle'>" />
									</td>
									</tr>
									<tr>
										<td class="formlabel"><LABEL class="reqlabel" for="dropApplication">Application:</LABEL><span class="form-required">*</span></td>
										<td align="left">	
									<asp:DropDownList ID="dropApplication" runat="server" DataTextField="appName" DataValueField="appID" SelectedValue='<%# Bind("appID") %>' />
                                    
		                           </td>
		                           <td><asp:RequiredFieldValidator runat="server" Display="Dynamic" ControlToValidate="dropApplication" ErrorMessage="<img src='images/common/required_trans.gif' align='absmiddle'>" />
									</td>
									</tr>
</table>
							</EditItemTemplate>	
 
 
----- codebehind
 
Sub dropComponent_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
 
        FormView1.ChangeMode(FormViewMode.Edit)
 
        Dim dropApplication As DropDownList = CType(FormView1.FindControl("dropApplication"), DropDownList)
        Dim dropComponent As DropDownList = CType(FormView1.FindControl("dropComponent"), DropDownList)
 
        dropApplication.Items.Clear()
 
        Dim objConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("APPdbConnectString").ConnectionString)
 
        Dim cmdSQL As New SqlCommand("dbo.P_applications_show_active", objConn)
 
        cmdSQL.CommandType = CommandType.StoredProcedure
        cmdSQL.Parameters.Add(New SqlParameter("@orgID", SqlDbType.INT, 4)).Value = dropComponent.SelectedItem.Value
 
        Dim sqlDR As SqlDataReader
 
        Try
            objConn.Open()
 
            sqlDR = cmdSQL.ExecuteReader(CommandBehavior.CloseConnection)
 
            dropApplication.DataSource = sqlDR
            dropApplication.DataBind()
        Catch myException As Exception
            Message.InnerHtml = "<tr><th height=""25"" class=""thmsg"" colspan=""3"" nowrap=""nowrap"">" & myException.ToString() & "</th></tr>"
 
        Finally
            If Not sqlDR Is Nothing Then
                sqlDR.Close()
            End If
            dropApplication.Items.Insert(0, New ListItem("-- Choose an application --", ""))
            dropApplication.SelectedIndex = 0
        End Try
 
    End Sub
[+][-]09/11/09 11:23 PM, ID: 25315416Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/12/09 03:47 PM, ID: 25318233Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/13/09 07:42 AM, ID: 25320364Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/13/09 09:48 AM, ID: 25320897Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/13/09 03:04 PM, ID: 25321967Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 12:20 AM, ID: 25323352Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 01:42 AM, ID: 25323640Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 08:24 AM, ID: 25326411Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 10:19 AM, ID: 25327454Expert Comment

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 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/14/09 11:04 AM, ID: 25327809Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/14/09 12:27 PM, ID: 25328473Accepted Solution

View this solution now by starting your 30-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

Zone: Programming for ASP.NET
Tags: ASP.NET, VB, Formview
Sign Up Now!
Solution Provided By: carlnorrbom
Participating Experts: 1
Solution Grade: A
 
[+][-]09/14/09 03:46 PM, ID: 25330002Author Comment

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 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625