Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am stumped and have been trying to find an answer for the last 3 days so I thought I would post a question.

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 is 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.NET
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
C#
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

C#
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;
        }


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.

Any help will be much appreciated.
Posted

Hi,

First Please Make sure

DataSet dsName in below code

C#
DataSet dsName = obj68.GetOneFIDM(strFIDMID);
 ddlCaseWorker.Text = dsName.Tables[0].Rows[0]["CaseWorker"].ToString();  


has Equal DataList of your DropdownList public DataSet GetCaseWorkerNames()

Because mentioned error occur when
for Example

dropdown List has value "John","Siva","Jenish" ad you tried to assign

ddlCaseworker.Text = "Siva K" means It Becomes Error.


Thanks

Siva Rm K
 
Share this answer
 
Comments
JTRizos 7-Nov-14 12:27pm    
Siva, thank you for the prompt response.

Yes, it is there. I should have included that code too. The code gets the Case record for update whcih includes the CaseWorker column and when the CaseWorker is not in the CaseWorker DropDownList because the person is no longer here, I get the error. The application works well except for this quark.

Here it is:


<pre lang="c#">
//** Called from UpdateFIDM
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;
}
I found the answer at this site

http://www.codeproject.com/Tips/770292/Preventing-DropDownList-Binding-Error?msg=4941212#xx4941212xx

Works great! I hope this helps others.

I appreciate the responses.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900