Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:19:37+00:00 2026-06-17T07:19:37+00:00

I am making a website (noob at this) and am trying to add search

  • 0

I am making a website (noob at this) and am trying to add search results to three divs. But problem arises when adding text to divs from database. It fetches correctly. but I want to convert a string (total three divs, id’s respectively being div1, div2, div3. string being “div” + DivCount.ToString, DivCount being 0 (which loops and +1 is added every loop) into command. Here’s the code, any other method would be appreciated too. Thanks. Code’s below, btw.

Default.aspx.vb

Imports Microsoft.VisualBasic
Imports System.Data.SqlServerCe

Partial Class Pages_Default
    Inherits System.Web.UI.Page

    'Project Variables
    Dim ProjectDirectory As String = AppDomain.CurrentDomain.BaseDirectory.ToString

    'ConnectAndAddItemsToDropdownList Dim
    Dim SQLCommandString As String
    Dim SQLConnectionString As String = "Data Source=" + ProjectDirectory + "App_Data\MainDatabase.sdf; Persist Security Info=False;"

    Dim SQLConnection As New SqlCeConnection(SQLConnectionString)
    Dim SQLAdapter As SqlCeDataAdapter
    Dim SQLReader As SqlCeDataReader
    Dim Executor As New MSScriptControl.ScriptControl

    Dim DivCount As Integer = 0
    Dim DivCurrent As String

    Public Sub ConnectAndAddItemsToDropdownList()
        DropDownList1.Items.Clear()
        SQLConnection.Open()
        SQLCommandString = "SELECT BookName FROM [Anthony Horowitz] WHERE (BookName LIKE '" + SearchTextBox.Text + "%')"
        Dim SQLCommand As New SqlCeCommand(SQLCommandString, SQLConnection)
        SQLReader = SQLCommand.ExecuteReader()
        While SQLReader.Read()
            DivCount = +1
            DivCurrent = "div" + DivCount.ToString
            Executor.Language = "VBScript"
            Executor.Eval(DivCurrent.ToString + ".InnerText = SQLReader(""Bookname"")")
        End While
        SQLConnection.Close()
    End Sub

    Protected Sub SearchTextChanged(sender As Object, e As EventArgs) Handles SearchTextBox.TextChanged
        ConnectAndAddItemsToDropdownList()
    End Sub
End Class

Default.aspx

<%@ Page Language="VB" CodeFile="Default.aspx.vb" Inherits="Pages_Default" AutoEventWireUp="False"%>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body id="MainPage" runat="server">
        <form id="form1" runat="server">
            <asp:TextBox ID="SearchTextBox" Text="Search for a book here..." runat="server" AutoPostBack="true" OnTextChanged="SearchTextChanged"></asp:TextBox>
            <asp:DropDownList ID="DropDownList1" runat="server" Height="17px" Width="105px"></asp:DropDownList>
            <div id="div1" runat="server">Nothing Interesting</div>
            <div id="div2" runat="server">Nothing Interesting</div>
            <div id="div3" runat="server">Nothing Interesting</div>
        </form>
    </body>
</html>

The result above is “object required: ‘div1′”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:19:39+00:00Added an answer on June 17, 2026 at 7:19 am

    You can’t get data like that and put it in elements, for three reasons:

    • The script doesn’t have access to your SQL Reader.
    • The elements doesn’t exist yet, all the server code has already ended before they do.
    • When the elements come to exist, they exist on a different computer.

    Put server controls in the markup where you want the text:

    <div id="div1" runat="server"><asp:Label runat="server" id="label1" Text="Nothing Interesting" /></div>
    

    Get references to the controls and put in an array so that you can easily access them:

    Dim labels(2) as Label
    labels(0) = label1
    labels(1) = label2
    labels(2) = label3
    

    Now you can put the data in the controls:

    While SQLReader.Read()
      labels(DivCount).Text = SQLReader("Bookname")
      DivCount = +1
    End While
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am a beginner in making website, i learned things at msdn only, but
Hey im making a website were you can send other users emails. My problem
I'm making a website Using JSF and richfaces, but I need to do some
I'm making this website, where I want to have a quote shown on the
I'm making a website with codeigniter. I'm trying to upload a blob via ajax.
I'm making website that have notification 'button'. When user click this button, notification div
I'm making a website and it is here: http://animactions.ca/Animactions/accueil.php My problem is when I
I am making a website that uses nothing but jquery-ui for theming. Well, in
I am making a website, where people can search for music (from YouTube), and
So I'm making a website for used goods. That is, a place where people

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.