Listview DropDownList FindControl没有编辑按钮

时间:2014-01-10 18:28:59

标签: asp.net listview drop-down-menu findcontrol sys-refcursor

当下拉列表嵌入到列表视图中时,我无法从数据集中填充下拉列表。我得到“对象引用未设置为对象的实例”。因为,我相信,我没有使用FindControl正确访问下拉列表

我们不希望在此列表视图上使用编辑按钮,我们希望每行都可以立即编辑。大多数在线示例都有编辑按钮。这可能是我问题的一部分。

大多数在线示例还使用ASPX页面中定义的数据源。我们一直使用Oracle.DataAccess sys_refcursor来填充数据集,然后使用数据集作为数据源。所以我必须从VB端填充下拉列表,而不是在aspx页面中使用数据源。

我可以独立填充列表视图,并独立填充下拉列表,但走路和口香糖是一个失败。

所以这里有一些我得到的片段:

<asp:ListView ID="lvMFGRS" runat="server">
    <ItemTemplate>
        <tr runat="server">
        <td runat="server">
           <asp:Label ID="NameLabel" runat="server" Text='<%#Eval("NEW_MANUFACTURER")%>' />
        </td>
        <td runat="server">
            <asp:dropdownlist ID="ddMFGRS"   runat="server" />
        </td>
        </tr>
    </ItemTemplate>
</asp:ListView>

然后在vb方面这样的事情:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   newmfglist() 'just sticks data in the "NameLabel" and databinds, and this works fine.
   For Each lvItem In lvMFGRS.Items
      Dim ddlist As DropDownList = lvMFGRS.FindControl("ddMFGRS")
         For Each tbl2 As DataTable In dsmfgrlist.Tables
             For Each dr2 As DataRow In tbl2.Rows
                Dim str1 As String
                Dim str2 As String
                str1 = "dog" 'dr2.Field(Of String)("DataValueField")
                str2 = "cat" 'dr2.Field(Of String)("DataTextField")
                ddlist.Items.Add(New ListItem(str2, str1))  'this is where I get the error
             Next
          Next
       Next

End Sub

那么你认为我做错了什么......

1 个答案:

答案 0 :(得分:0)

答案是:

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   newmfglist() 'just sticks data in the "NameLabel" and databinds, and this works fine.
   For Each lvItem In lvMFGRS.Items
      Dim ddlist As DropDownList = lvItem.FindControl("ddMFGRS")
         For Each tbl2 As DataTable In dsmfgrlist.Tables
             For Each dr2 As DataRow In tbl2.Rows
                Dim str1 As String
                Dim str2 As String
                str1 = "dog" 'dr2.Field(Of String)("DataValueField")
                str2 = "cat" 'dr2.Field(Of String)("DataTextField")
                ddlist.Items.Add(New ListItem(str2, str1))  'this is where I get the error
             Next
          Next
       Next