我在這個論壇上是新的,雖然我已經通過多年尋找答案。現在,我會喜歡你的幫助來解決問題。我下面這個link使自己的下拉列表中我的網格和正常工作,直到這條線:ASP:NET - GridView的 - DropDownList selectedvalue
ddlCities.Items.FindByValue(country).Selected = True
在這裏,我有錯誤:
Object reference not set to an instance of an object.
,但我的代碼是正確的,受影響的領域:
這是代碼相關的代碼背後:
Protected Sub RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow AndAlso grdLinea.EditIndex = e.Row.RowIndex;
Dim ddlCities As DropDownList = DirectCast(e.Row.FindControl("ddlFacturarA"), DropDownList)
' Create the command with the sproc name and add the parameter required'
ddlCities.DataSource = GetData("select UPPER(DSCA_ZONA)as Zona from tb_personal where dsca_Zona <> 'NULL'group by dsca_zona order by dsca_zona")
ddlCities.DataTextField = "Zona"
ddlCities.DataValueField = "Zona"
ddlCities.DataBind()
'Add Default Item in the DropDownList
'ddlCountries.Items.Insert(0, New ListItem("Please select"))
Dim country As String = Trim(CType(e.Row.FindControl("lblFacturarA"), Label).Text)
ddlCities.Items.FindByValue(country).Selected = True
End If
End Sub
,這是AFF在設計模式ected代碼:
<EditItemTemplate >
<asp:label ID="lblFacturarA" Value ='<%# Eval("facturar_a")%>' Visible ="false" runat="server" />
<asp:DropDownList
ID="ddlFacturarA"
CssClass="txt"
runat="server"
AutoPostBack="True" ValidationGroup="rfNewLineEmpty">
</asp:DropDownList>
<asp:RequiredFieldValidator
ID="rfNewLineFacturarA"
runat="server"
ErrorMessage="Obligatorio"
ValidationGroup="rfNewLine"
SetFocusOnError="True"
ControlToValidate="ddlFacturarA">
</asp:RequiredFieldValidator>
</EditItemTemplate>
我知道我在ASP.NET新,也許我的方式失去的東西,但我一直在這一輪代碼兩天並沒有看到光。
你能告訴我關於這個錯誤的原因嗎?
請讓我知道你是否需要更詳細的信息來解決這個問題。
在此先感謝
你能找到Lable嗎? –
是的,即使我已經使它可見。如果我註釋這行代碼,dropdownlist加載正常。當試圖從數據庫作爲組合的選擇值時,問題出現在組合 –
您的意思是說國家字符串有一些價值是在標籤lblFacturarA,對不對? –