我搜索了一个以两种方式之一调用的数据库,
第一个是回发事件,来自搜索字段\文本框和按钮单击事件,另一个是来自查询字符串。两者都调用相同的方法,并将结果数据传递到一个方法,该方法应该使用返回的值填充下拉列表和文本框。
我遇到的问题是当我使用如下所示的查询字符串进行搜索时
If Not Page.IsPostBack And Not String.IsNullOrEmpty(Request.QueryString("CaseId")) Then
GetCaseInfo(Request.QueryString("CaseId"), True)
End If
我用来获取按钮上的caseId的代码是
Protected Sub SearchCase(sender As Object, e As EventArgs) Handles bttnSearchCase.Click
GetCaseInfo(txtCaseSearchId.Text, True)
End Sub
我进入行If Not dt(0)("AmendmentsToAccount") Is DBNull.Value Then ddlAmendmentsOnAccount.SelectedIndex = Convert.ToInt16(dt(0)("AmendmentsToAccount")) Else ddlAmendmentsOnAccount.SelectedIndex = 0
,然后下拉列表的所有SelectedIndex
es返回0 ddlReason
除外。
然而,当使用文本框搜索并单击进入相同方法的按钮时,所有正确的值都会保留。
正在更改所选索引的代码是
If Not dt(0)("EvidenceCaseCorrect") Is DBNull.Value Then ddlEvidenceCorrect.SelectedIndex = Convert.ToInt16(dt(0)("EvidenceCaseCorrect")) Else ddlEvidenceCorrect.SelectedIndex = 0
If Not dt(0)("ApplicationOnFile") Is DBNull.Value Then ddlApplicationOnFile.SelectedIndex = Convert.ToInt16(dt(0)("ApplicationOnFile")) Else ddlApplicationOnFile.SelectedIndex = 0
If Not dt(0)("RemediationRequired") Is DBNull.Value Then ddlRemediationRequired.SelectedIndex = Convert.ToInt16(dt(0)("RemediationRequired")) Else ddlRemediationRequired.SelectedIndex = 0
If Not dt(0)("Reason") Is DBNull.Value Then ddlListReason.SelectedValue = Convert.ToInt16(dt(0)("Reason")) Else ddlListReason.SelectedValue = 0
If Not dt(0)("ScoredCorrectly") Is DBNull.Value Then ddlScoreCorrectly.SelectedIndex = Convert.ToInt16(dt(0)("ScoredCorrectly")) Else ddlScoreCorrectly.SelectedIndex = -0
If Not dt(0)("TransmittedCorrectly") Is DBNull.Value Then ddlTransmittedCorrectly.SelectedIndex = Convert.ToInt16(dt(0)("TransmittedCorrectly")) Else ddlTransmittedCorrectly.SelectedIndex = 0
If Not dt(0)("ArrearsFlagPresent") Is DBNull.Value Then ddlAreas.SelectedIndex = Convert.ToInt16(dt(0)("ArrearsFlagPresent")) Else ddlAreas.SelectedIndex = 0
txtRetirementAge.Text = dt(0)("RetirementAge").ToString()
If Not dt(0)(10) Is DBNull.Value Then ddlBreach.SelectedIndex = Convert.ToInt16(dt(0)("Breach")) Else ddlBreach.SelectedIndex = 0
txtOriginalAdvice.Text = dt(0)("OriginalAdvance").ToString()
txtCompletionDate.Text = dt(0)("CompletionDate").ToString()
txtInterestRate.Text = dt(0)("InterestRate").ToString()
txtDateAppliedTo.Text = dt(0)("DatesAppliedFrom").ToString() 'change name on field and a new field here
txtDateAppliedFrom.Text = dt(0)("DatesAppliedTo").ToString() 'change name on field and a new field here
txtCorrectTerm.Text = dt(0)("CorrectTerm").ToString()
txtTermCompletion.Text = dt(0)("TermAtCompletion").ToString()
txtRemainignTerm.Text = dt(0)("RemainingTerm").ToString()
txtDiffInTerm.Text = dt(0)("DifferenceInTerm").ToString()
If Not dt(0)("AmendmentsToAccount") Is DBNull.Value Then ddlAmendmentsOnAccount.SelectedIndex = Convert.ToInt16(dt(0)("AmendmentsToAccount")) Else ddlAmendmentsOnAccount.SelectedIndex = 0
将所选索引值转换为in16变量的原因是当它进入时因为它被记录为数字而被视为布尔值而不是整数值。
我遇到的问题是为什么在上面提到的那一行上,除了一个之外,它还将所有下拉列表中选定的索引值重置为0?