Tony

Tony

  • NA
  • 30
  • 0

dropdownlist has a SelectedValue which is invalid

Nov 7 2014 1:32 PM
I am stumped and have been trying to find an answer for the last 3 days so I thought I would post a question.  The error I get is:

'ddlCaseWorker' has a SelectedValue which is invalid because it does not exist in the list of items.  Parameter name: value
 
I have an ASP.Net application with a dropdownlist that gets it's entries (list of Case Worker names) from an SQL Case Worker table. Once selected from the list the record is saved in a Case table along with other relevant Case data. For example: Case Worker John Smith is now in the Case table.
 
If the record is brought back up for update, the dropdownlist is repopulated. There is no problem if John Smith is still in the Case Worker table. If John Smith if no longer with us and removed from the Case Worker table so he can't be selected from the dropdownlist, then I get the above error when I try opening the Case record for update since John Smith is still in the Case record. I hope this makes sense. I do not know how to get around this and everything I have tried does not work.
 
Here is the relevant code
 
UpdateFIDM.aspx

asp:DropDownList ID="ddlCaseWorker" runat="server"  Font-Size="X-Small"
            DataSourceID="odsCaseWorker" DataTextField="Fullname"
            AppendDataBoundItems="true"
            DataValueField="Fullname" OnLoad="Page_Load"  Width="200px">
        </asp:DropDownList>
       
        <!-- data source for the Case Worker drop down list -->
        <asp:ObjectDataSource ID="odsCaseWorker" runat="server"
            SelectMethod="GetCaseWorkerNames" TypeName="OmbudsBAL.OmbudsBAL">
        </asp:ObjectDataSource>

Code Behind UpdateFIDM.aspx.cs

if (!Page.IsPostBack)
        {
            //*  Grab the ID that was Passed *//
            string strFIDMID = Request.QueryString["FIDMID"];
            // get data for this FIDMID to populate update fields
            OmbudsBAL.OmbudsBAL obj68 = new OmbudsBAL.OmbudsBAL();
            DataSet dsName = obj68.GetOneFIDM(strFIDMID);
            txtFIDMID.Text = dsName.Tables[0].Rows[0]["FIDMID"].ToString();
            ddlFIDMStatus.Text = dsName.Tables[0].Rows[0]["FIDMStatus"].ToString();
            ddlCaseWorker.Text = dsName.Tables[0].Rows[0]["CaseWorker"].ToString();         txtCSENumber.Text = dsName.Tables[0].Rows[0]["CSENumber"].ToString();
            ddlCounty.Text = dsName.Tables[0].Rows[0]["County"].ToString();
            txtNCPName.Text = dsName.Tables[0].Rows[0]["NCPName"].ToString();
            ddlEOTWOTW.Text = dsName.Tables[0].Rows[0]["EOTWOTW"].ToString();
            txtFinancialInstitution.Text = dsName.Tables[0].Rows[0]["FinancialInstitution"].ToString();
            txtBankNumber.Text = dsName.Tables[0].Rows[0]["BankNumber"].ToString();
            ddlAssetType.Text = dsName.Tables[0].Rows[0]["AssetType"].ToString();
            txtSourceofFunds.Text = dsName.Tables[0].Rows[0]["SourceofFunds"].ToString();
            ddlNCPClaim.Text = dsName.Tables[0].Rows[0]["NCPClaim"].ToString();
            ddlLCSAResolution.Text = dsName.Tables[0].Rows[0]["LCSAResolution"].ToString();
            ddlResolutionType.Text = dsName.Tables[0].Rows[0]["ResolutionType"].ToString();
            ddlSuppressionLength.Text = dsName.Tables[0].Rows[0]["SuppressionLength"].ToString();
            ddlCourtType.Text = dsName.Tables[0].Rows[0]["CourtType"].ToString();
            txtTimeSpent.Text = dsName.Tables[0].Rows[0]["TimeSpent"].ToString();
            txtNotes.Text = dsName.Tables[0].Rows[0]["Notes"].ToString();

Get the Case Worker names for the dropdownlist

public DataSet GetCaseWorkerNames()
        {
            query = "SELECT EmployeeNameFirst + ' ' + EmployeeNameLast as Fullname, " +
                "Employee.EmployeeID, " +
                "JobUnitGroup " +
                "FROM Employee " +
                "join Job on Employee.EmployeeID = Job.EmployeeID " +
                "left join JobUnit on Job.JobUnitID = JobUnit.JobUnitID " +
                "left join JobTitle on Job.JobTitleID = JobTitle.JobTitleID " +
                //Temporary - will need FIDM added to JobUnit table if deployed to toher areas
                //"where ((JobUnitGroup = 'FIDM') " +
                "where ((Job.JobUnitID in (13,14,29)) " +
                "and JobStatusCode = 'AC') " +
                "or Employee.EmployeeID in (478) " +
                "order by Fullname ";
            DataSet ds = obj65.getData(query, connection);
            return ds;
        }

Get the Case record

//** Called from UpdateFIDM.ASPX.CS
public DataSet GetOneFIDM(string strFIDMID)
{
query = "SELECT FIDMID, " +
"FIDMStatus, " +
"CaseWorker, " +
"NCPName, " +
"CSENumber, " +
"CallReceivedDate = CASE CallReceivedDate WHEN '01/01/1900' THEN null ELSE CallReceivedDate END, " +
"MultiCountyCase, " +
"LevyDate = CASE LevyDate WHEN '01/01/1900' THEN null ELSE LevyDate END, " +
"EOTWOTW, " +
"AssetType, " +
"FinancialInstitution, " +
"BankNumber, " +
"AmountInAccount, " +
"LevyAmount, " +
"ArrearsBalance, " +
"SourceofFunds, " +
"NCPClaim, " +
"LCSAResolution, " +
"ResolutionType, " +
"Collection, " +
"COESent, " +
"COEReturnDate = CASE COEReturnDate WHEN '01/01/1900' THEN null ELSE COEReturnDate END, " +
"CourtDate = CASE CourtDate WHEN '01/01/1900' THEN null ELSE CourtDate END, " +
"CourtType, " +
"ResolutionDate = CASE ResolutionDate WHEN '01/01/1900' THEN null ELSE ResolutionDate END, " +
"Suppression, " +
"SuppressionLength, " +
"TimeSpent, " +
"Notes, " +
"County, " +
"FIDM.Added, " +
"FIDM.AddedBy, " +
"FIDM.Updated, " +
"FIDM.UpdatedBy " +
"from FIDM " +
"where FIDMID = '" + strFIDMID + "' ";
DataSet ds = obj68.getData(query, connection);
return ds;
}

To complicate the problem is that the application will be populated from an Access table with data going back 5 years so many of the Case Workers are no longer here and would not be found when building the dropdownlist entries.

Other than for this condition the application has no other problems.
 
Any help will be much appreciated.

Answers (2)