我写了一个类似下面的脚本,我的表记录显示在图片中。
Dim objDataTable As System.Data.DataTable = _objCommonData.fnLoadCompanyList(1)
ddlCompany.DataSource = objDataTable
ddlCompany.DataTextField = "company_name"
ddlCompany.DataValueField = "id"
ddlCompany.DataBind()
我写了这样的东西,
If ddlCompany.SelectedValue = "" Then
strCompany = "0"
ElseIf ddlCompany.SelectedValue = "0" Then
strCompany = "0"
Else
strCompany = ddlCompany.SelectedValue
End If
我错过了什么?它不断返回strCompany = 1
。
答案 0 :(得分:3)
您可能需要这样做:
If (Not Page.IsPostBack) Then
Dim objDataTable As System.Data.DataTable = _objCommonData.fnLoadCompanyList(1)
ddlCompany.DataSource = objDataTable
ddlCompany.DataTextField = "company_name"
ddlCompany.DataValueField = "id"
ddlCompany.DataBind()
End If
有时会出现此问题,因为列表每次绑定并清除重新绑定时的选择。