html
iphone
css
c
python
linux
android
objective-c
visual-studio
multithreading
html5
perl
cocoa
tsql
apache
mvc
php5
api
postgresql
dom
The problem can be if tlbEmployee columns in the SqlDSProfile in the update statement and field names used by your controls do not match. Other procedures you've followed are right.
tlbEmployee
SqlDSProfile
SqlDataSource control expects field names it updates to be similar with those bound to the controls(fields) inside the DataBound control. The Solution can be: change all the update Parameters to ControlParameters referencing the right control for each one
SqlDataSource control expects field names it updates to be similar with those bound to the controls(fields) inside the DataBound control.
Parameters
ControlParameter
Update: Wait, I think the problem is your select statement of the SqlDSProfile should contain: CurrentDeptID and CurrentJobID. Try it:
CurrentDeptID
CurrentJobID
<asp:SqlDataSource ID="sqlDSProfile" runat="server" ConnectionString="<%$ ConnectionStrings:JobsDB %>" SelectCommand="SELECT tblEmployee.EUID, tblEmployee.DateHired, tblEmployee.LastName, tblEmployee.HiredLastName, tblEmployee.FirstName, tblEmployee.Role, tblEmployee.JobGrade, tblDepartments.Department, tblJobs.JobName, tblEmployee.CurrentShift, tblEmployee.JobDate, tblEmployee.IsDisplaced, tblEmployee.EligibilityDate tblEmployee.CurrentDeptID, tblEmployee.CurrentJobID FROM tblEmployee
Advice: Test your code portion by portion. Try the code without the dropdownlist, Test separately Add the one drop downlist Use select * from ... in select queries Avoid ajax when testing If you make it Add portions of code portion after portion at last use the partial updating (ajax)
I have a working solution now, thanks in part to Nuux and a bunch of online research. The tip about the join statement wasn't relevant, but the tip about including "CurrentJobID" and "CurrentDeptID" in my select query was spot on.
In addition to that I had to rework the controls a little. The two cascading dropdownlists are below. The ddlJobs dropdown list behaves like a normal databound control, but it doesn't have the Bind("CurrentJobID") statement I was trying in my original post.
<asp:DropDownList ID="ddlDepartments" runat="server" Width="185px" DataSourceID="sqlDSDepartments" DataTextField="Department" DataValueField="DeptID" SelectedValue='<%# Bind("CurrentDeptID") %>' AppendDataBoundItems="true" AutoPostBack="True" > <asp:ListItem Text="--Select One--" Value="" /> </asp:DropDownList> <asp:DropDownList ID="ddlJobs" runat="server" Width="185px" DataSourceID="sqlDSJobs" DataTextField="JobName" DataValueField="JobID" AppendDataBoundItems="true" OnDataBinding="ddlJobs_DataBinding" />
The only thing the custom routine "ddlJobs_DataBinding" is doing is adding "--Select One--" as index 0 in the ddlJobs dropdown. I tried this in several places, like page_load, and the databound event of the formview with no success.
Protected Sub ddlJobs_DataBinding(sender As Object, e As System.EventArgs) Dim ddlJobs As DropDownList = frmProfile.FindControl("ddlJobs") Dim liSelectOne As New ListItem("--Select One--", 0) ddlJobs.Items.Clear() ddlJobs.Items.Insert(0, liSelectOne) End Sub
The databound event of the formview frmProfile_DataBound event does do some work though. When the user clicks "edit" on the formview to enter editing mode this ensures that the dropdownlist ddlJobs has the correct job selected by default for the profile in question. If the user hasn't been assigned to a job then it defaults to selectedindex 0 which is "--Select One--" set in custom databinding event just above.
Protected Sub frmProfile_DataBound(sender As Object, e As System.EventArgs) Handles frmProfile.DataBound If frmProfile.CurrentMode = FormViewMode.Edit Then Dim ddlJobs As DropDownList = frmProfile.FindControl("ddlJobs") Dim dvProfile As DataView = sqlDSProfile.Select(DataSourceSelectArguments.Empty) Dim drProfile As DataRow = dvProfile.Table.Rows(0) If drProfile("CurrentJobID").ToString() = "" Then ddlJobs.SelectedIndex = 0 Else ddlJobs.SelectedValue = drProfile("CurrentJobID").ToString() End If End If End Sub
Finally, if the user selects a new job from ddlJobs, that value has to be fed to the database, which the ItemUpdating event of the formview handles.
Protected Sub frmProfile_ItemUpdating(sender As Object, e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles frmProfile.ItemUpdating If frmProfile.CurrentMode = FormViewMode.Edit Then Dim ddlJobs As DropDownList = frmProfile.FindControl("ddlJobs") e.NewValues("CurrentJobID") = ddlJobs.SelectedValue End If End Sub
Done!