DropdownList使用listview进行数据处理

时间:2015-11-27 10:09:48

标签: asp.net vb.net listview data-binding

我正在尝试将dropdownlist与mysql数据库列绑定,但无法实现它。得到此错误

ERROR :  BC30451: 'fetchOrder' is not declared. It may be inaccessible due to its protection level.

ASPX

<asp:ListView ID="driversData" runat="server" DataKeyNames="DriverID" >
                            <EditItemTemplate>
                                <tr>
                                    <td>
                                        <asp:DropDownList ID="fetchOrder" runat="server">
                                        </asp:DropDownList>
                                    </td>
                                    <td>
                                        Submit
                                    </td>
                                </tr>
                            </EditItemTemplate>



                            <EmptyDataTemplate>
                                <div style="text-align: center" class="list-item-box">
                                    <strong>Oops...No Record Found...</strong>
                                </div>
                            </EmptyDataTemplate>
                            <LayoutTemplate>
                                <ul id="itemPlaceholderContainer" runat="server" style="margin: 0; padding: 0">
                                    <li runat="server" id="itemPlaceholder" />
                                </ul>
                                <div style="margin: 0; padding: 0">
                                    <asp:DataPager ID="DataPager1" runat="server" PageSize="50" PagedControlID="driversData"
                                        ViewStateMode="Enabled">
                                        <Fields>
                                            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True"
                                                ButtonCssClass="last" />
                                        </Fields>
                                    </asp:DataPager>
                                </div>
                            </LayoutTemplate>
                        </asp:ListView>

VB

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        addDriver.Visible = False
        autogenerate_id()
        Try
            ViewState("Data") = ""
            Using con As New MySqlConnection(constr)
                Using cmd As New MySqlCommand("SELECT * FROM addDriver ")
                    Using sda As New MySqlDataAdapter()
                        cmd.Connection = con
                        sda.SelectCommand = cmd
                        cmd.CommandTimeout = 0
                        Using dt As New DataTable()
                            sda.Fill(dt)
                            ViewState("Data") = dt
                            driversData.DataSource = dt
                            driversData.DataBind()

                        End Using
                    End Using
                End Using
            End Using

            'countResult.Text = (" " & schoollists.Items.Count & " " & board.Text & " Schools Found in " & area.Text & " ")

        Catch ex As Exception
            Response.Write(ex)
        End Try

        If Not Me.IsPostBack Then
            Using con As New MySqlConnection(constr)
                Using cmd As New MySqlCommand("SELECT Bid FROM newBooking")
                    cmd.CommandType = CommandType.Text
                    cmd.Connection = con
                    con.Open()
                    fetchOrder.DataSource = cmd.ExecuteReader()
                    fetchOrder.DataTextField = "Bid"
                    fetchOrder.DataBind()
                    con.Close()
                End Using
            End Using
            fetchOrder.Items.Insert(0, New ListItem("--Select Customer--", "0"))
        End If
    End Sub

如果我不使用列表视图&amp;应用相同的代码然后它工作正常。我想还有一些需要在listview中应用它。任何人都可以帮助我实现它..

1 个答案:

答案 0 :(得分:0)

好吧,错误告诉你fetchOrder根本没有声明,或者如果你有,那么你可能没有用正确的范围声明它 - 例如私人,朋友等