如何处理'ddlCaseWorker'的SelectedValue无效,因为它在项目列表中不存在。 [英] How do I handle 'ddlCaseWorker' has a SelectedValue which is invalid because it does not exist in the list of items.

查看:78
本文介绍了如何处理'ddlCaseWorker'的SelectedValue无效,因为它在项目列表中不存在。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难过,并且一直试图找到过去3天的答案,所以我想我会发一个问题。



我有一个ASP.Net带有下拉列表的应用程序,它从SQL Case Worker表中获取它的条目(Case Worker名称列表)。从列表中选择后,记录将与其他相关案例数据一起保存在案例表中。例如:Case Worker John Smith现在位于Case表中。



如果记录被重新更新,则会重新填充下拉列表。 John Smith仍然在Case Worker表中没有问题。如果John Smith不再与我们一起并从Case Worker表中删除所以无法从下拉列表中选择,那么当我尝试打开Case记录进行更新时,我得到了上述错误,因为John Smith仍在Case记录中。我希望这是有道理的。我不知道怎么解决这个问题,我尝试的一切都行不通。



这是相关代码



UpdateFIDM.aspx



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: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>





UpdateFIDM.aspx.cs背后的代码



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();





获取下拉列表中的Case Worker名称





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





使问题复杂化的是,应用程序将从Access表填充,数据可以追溯到5年前许多案例工作者不再在这里,在构建下拉列表条目时也不会找到。



任何帮助将不胜感激。



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.

推荐答案

您好,



首先请确保



DataSet dsName在下面的代码中



Hi,

First Please Make sure

DataSet dsName in below code

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





具有DropdownList公共DataSet的Equal DataList GetCaseWorkerNames()



因为提到的错误发生在

例如



下拉列表中有值John,Siva,Jenish广告你试过分配



ddlCaseworker.Text =Siva K意味着它会出错。





谢谢



Siva Rm K



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


我在这个网站找到答案



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



效果很好!我希望这有助于其他人。



我很感激回复。
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.


这篇关于如何处理'ddlCaseWorker'的SelectedValue无效,因为它在项目列表中不存在。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆