Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Formview - Binding to edit

Posted on 2009-05-05
3
Medium Priority
?
539 Views
Last Modified: 2012-05-06
My formview is having an issue. I have two dropdown boxes. Facility and Department. The department list is dependent facility. So I call the facility and then then pull the department where facility is equal to what is in that first dropdown. For example..  First dropdown box is Microsoft and the dropdown list all the departments. Then I  using SelectedValue = (Bind etc etc)  to get the specific Facility (Microsoft) and department that is associated with the formview record.
This all works fine.
Now the issue.  If the user wants to edit that facility or department, it does not work. I get an error on the Bind.  Because when I change the facility, the department list needs to change and the Bind is no longer valid.  
So how do I get the field to unbind from the formview when the facility is changed?
If it is not possible, suggestions on how make this form user friendly.  

This form is create by a user.  When they submit it, another user gets the email.  That user logs in and looks at the original submission and they may need to make changes like directly informaton to a differnt department.

0
Comment
Question by:aninec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Expert Comment

by:NazoUK
ID: 24315077
Yeah, this is a known issue with the way databinding works and a bit awkward to get around.
What I tend to do is remove the SelectedValue = '<%#Bind.....' from the dropdownlist that has its items updated, then in the OnUpdating event of whichever datasource type you are using manually get the value out of the formview using FindControl and plug that into the updateparameters, business object or whatever you are using.

It's a bit difficult to give a concrete example without knowing the datasource you are using. Is it a sqldatasource, object data source etc?
0
 

Author Comment

by:aninec
ID: 24318887
Its SQL.  I am not sure how to approach your method.  
0
 
LVL 15

Accepted Solution

by:
NazoUK earned 2000 total points
ID: 24323636
OK, in your sqldatasource add the following: OnUpdating="sqlds_Updating" OnInserting="sqlds_Updating"
You'll also need a parameter in updateparameters and insertparameters that correspond to the field name:

<asp:Parameter Name="fieldName" Type="Int32" DefaultValue="0" />

Then in your code behind add a method to handle this event and get the values out of the FormView and put them into the parameters:

C#:

    protected void sql1_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
             DropDownList dd = (DropDownList) yourFormView.FindControl("DropDownName");
             e.Command.Parameters["fieldName"].Value = Convert.ToInt32(dd.SelectedValue);
    }

VB:

    Protected Sub sql1_updating(sender as object, e as SqlDataSourceCommandEventArgs)
    {
            Dim dd as DropDownList = Ctype(yourFormView.FindControl("DropDownName"),DropDownList)
            e.Command.Parameters("fieldName").Value = CInt(dd.SelectedValue)
    }

This assumes your dropdowns store int values, if not you'll need to change the code as appropriate.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question