我在这个论坛上是新的,虽然我已经通过多年寻找答案。现在,我会喜欢你的帮助来解决问题。我下面这个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,对不对? –