0

I am trying to bind dropdownlist with mysql database column but not able to achieve it. Getting this error

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

If I don't use list view & apply same code then it works fine. I guess there is some addition needed top apply it in listview. Can anybody help me to achive it..

  • as per your error, it seems there is a security issue. Your folder has some accessible rights which is not allowing it to open – Nad Nov 27 '15 at 10:11
  • @coder Thanks for your reply. But if I don't use listview & use dripdownlist directly then it is working fine. –  Nov 27 '15 at 10:14
  • Possible duplicate of [Accessing controls in the edititemtemplate of a listview](http://stackoverflow.com/questions/825048/accessing-controls-in-the-edititemtemplate-of-a-listview) – stuartd Nov 27 '15 at 10:46

1 Answers1

0

Well, the error is telling you that either fetchOrder isn't declared at all, or if you have, then you probably haven't declared it with the correct scope - e.g. Private,Friend etc

David Wilson
  • 4,369
  • 3
  • 18
  • 31