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 7987551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:10:55+00:00 2026-06-04T12:10:55+00:00

I want to make my dropdownlist selected first value –select– when first load page

  • 0

I want to make my dropdownlist selected first value “–select–” when first load page as i need to force user to choose an event from list. I am blur since I need to perform other function at page_load to check checkbox enable properties, so that I not sure where should I put the coding to Add empty value to dropdownlist.

I did put the following code in page load but nothing happen, the “-select- also no appear in the dropdownlist.

If Not Page.IsPostBack Then

        ddlEventTitle.Items.Insert(0, New ListItem("-select-", String.Empty))

    End If

What should I do to modify my coding?

client code:

<%@ Page Language="VB" MasterPageFile="~/MasterPageAdmin.master" AutoEventWireup="false" CodeFile="addbooth.aspx.vb" Inherits="addbooth" title="Untitled Page" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

<asp:Content ID="ContentPlaceHolder2" runat="server" 
contentplaceholderid="ContentPlaceHolder2">

 <table class="style8" cellpadding="3">
 <tr>
 <td class="style9">Add New Booth</td>
 <td>&nbsp;</td>
 </tr>
 <tr>
 <td class="style9">&nbsp;</td>
 <td>&nbsp;</td>
 </tr>
 <tr>
 <td class="style9">Event Title:</td>
 <td>
 <asp:SqlDataSource ID="SqlDataSourceEventTitle" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" SelectCommand="SELECT DISTINCT [eventID], [eventTitle] FROM [eventinfo]">
 </asp:SqlDataSource>
 <asp:DropDownList ID="ddlEventTitle" runat="server" DataSourceID="SqlDataSourceEventTitle" DataTextField="eventTitle" DataValueField="eventID" Width="240px" AutoPostBack="True">
 </asp:DropDownList>
 </td>
 </tr>
 <tr>
 <td class="style9">Booth Alias:</td>
 <td>
 <asp:TextBox ID="txtBoothAlias" runat="server" Width="235px"></asp:TextBox>
 </td>
 </tr>
 <tr>
 <td class="style9"> Booth Type:</td>
 <td>
 <asp:DropDownList ID="ddlBoothType" runat="server" Width="240px" AutoPostBack="True">
 <asp:ListItem Value="7">8&#39;x8&#39;</asp:ListItem>
 <asp:ListItem Value="10">9&#39;x8&#39;</asp:ListItem>
 <asp:ListItem Value="11">12&#39;x50&#39;</asp:ListItem>
 <asp:ListItem Value="12">16&#39;x10&#39;</asp:ListItem>
 <asp:ListItem Value="13">20&#39;x16&#39;</asp:ListItem>
 <asp:ListItem Value="15">32&#39;x10&#39;</asp:ListItem>
 <asp:ListItem Value="17">32&#39;x14.5&#39;</asp:ListItem>
 </asp:DropDownList>
 </td>
 </tr>
 <tr>
 <td class="style10" valign="top" colspan="2">Booth Duration:<br />
 <font size="2">Tick to activate availability</font></td>
 </tr>
 <tr>
 <td class="style10" valign="top" colspan="2" align="center">
 <asp:Panel ID="Panel1" runat="server" Width="328px" Direction="LeftToRight" HorizontalAlign="Center">
 <table cellpadding="5" class="style8">
 <tr>
 <td>
 <asp:CheckBox ID="cbWeek1" runat="server" Text="Week 1" TextAlign="Left" OnCheckedChanged="cbWeek1_CheckedChanged" AutoPostBack="true"/>
  </td>
  <td>
 <asp:CheckBox ID="cbWeek2" runat="server" Text="Week 2" TextAlign="Left" OnCheckedChanged="cbWeek2_CheckedChanged" AutoPostBack="true"/>
   </td>
   <td>
  <asp:CheckBox ID="cbWeek3" runat="server" Text="Week 3" TextAlign="Left" OnCheckedChanged="cbWeek3_CheckedChanged" AutoPostBack="true"/>
   </td>
    <td>
 <asp:CheckBox ID="cbWeek4" runat="server" Text="Week 4" TextAlign="Left" OnCheckedChanged="cbWeek4_CheckedChanged" AutoPostBack="true"/>
                                                                                </td>
                                                                            </tr>
                                                                            <tr>
                                                                                <td>
                                                                                             <asp:CheckBox ID="cbWeek5" runat="server" Text="Week 5" TextAlign="Left" OnCheckedChanged="cbWeek5_CheckedChanged" AutoPostBack="true"/>
                                                                                </td>
                                                                                <td>
                                                                                              <asp:CheckBox ID="cbWeek6" runat="server" Text="Week 6" TextAlign="Left" OnCheckedChanged="cbWeek6_CheckedChanged" AutoPostBack="true"/>
                                                                                </td>
                                                                                <td>
                                                                                              <asp:CheckBox ID="cbWeek7" runat="server" Text="Week 7" TextAlign="Left" OnCheckedChanged="cbWeek7_CheckedChanged" AutoPostBack="true"/>
                                                                                </td>
                                                                                <td>
                                                                                              <asp:CheckBox ID="cbWeek8" runat="server" Text="Week 8" TextAlign="Left" OnCheckedChanged="cbWeek8_CheckedChanged" AutoPostBack="true"/>
                                                                                </td>
                                                                            </tr>
                                                                        </table>

  </asp:Panel>
  <asp:RoundedCornersExtender ID="Panel1_RoundedCornersExtender"runat="server" Enabled="True" TargetControlID="Panel1" BorderColor="CadetBlue" Color="ButtonFace">
 </asp:RoundedCornersExtender>
       </td>
       </tr>
       <tr>
        <td class="style11">
         </td>
         <td class="style11">
 <asp:Button ID="ButtonAddNewBooth" runat="server" Text="Add New Booth"  Height="50px" />
 </td>
 </tr>
   <tr>
    <td class="style9"> &nbsp;</td>
     <td>&nbsp;</td>
       </tr>
         <tr>
 <td class="style9" colspan="2">
 <asp:GridView ID="GridViewBoothAdded" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSourceBoothAdded" Font-Size="Small" ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize="5" Visible="False">
 <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
 <Columns>
  <asp:BoundField DataField="boothAlias" HeaderText="Booth Alias" SortExpression="boothAlias" />
 <asp:BoundField DataField="week1" HeaderText="week1" SortExpression="week1" />
 <asp:BoundField DataField="week2" HeaderText="week2" SortExpression="week2" />
 <asp:BoundField DataField="week3" HeaderText="week3" SortExpression="week3" />
 <asp:BoundField DataField="week4" HeaderText="week4" SortExpression="week4" />
 <asp:BoundField DataField="week5" HeaderText="week5" SortExpression="week5" />
 <asp:BoundField DataField="week6" HeaderText="week6" SortExpression="week6" />
 <asp:BoundField DataField="week7" HeaderText="week7" SortExpression="week7" />
 <asp:BoundField DataField="week8" HeaderText="week8" SortExpression="week8" />
  </Columns>
  <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
  <EmptyDataTemplate>
        No booth record
  </EmptyDataTemplate>
  <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
  <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="Small" ForeColor="White" />
  <EditRowStyle BackColor="#999999" />
  <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
   </asp:GridView>
   <asp:RoundedCornersExtender ID="GridViewBoothAdded_RoundedCornersExtender" runat="server" Enabled="True" TargetControlID="GridViewBoothAdded">
    </asp:RoundedCornersExtender>
    <asp:SqlDataSource ID="SqlDataSourceBoothAdded" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" 
    SelectCommand="SELECT [week1], [week2], [week3], [week4], [week5], [week6], [week7], [week8], [eventID], [boothAlias], [eventTitle] FROM [booth_eventinfo] WHERE ([eventID] = @eventID)">
   <SelectParameters>
    <asp:ControlParameter ControlID="ddlEventTitle" Name="eventID" PropertyName="SelectedValue" Type="Int32" />
   </SelectParameters>
   </asp:SqlDataSource>
                                                                </td>
                                                            </tr>
   </table>

server code:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Threading
Imports System.Object
Partial Class addbooth
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not Page.IsPostBack Then

        ddlEventTitle.Items.Insert(0, New ListItem("-select-", String.Empty))

    End If

    Dim eventID As String = ddlEventTitle.SelectedValue
    Dim connString As String = ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString
    ' Dim connString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CikguTube3.mdf;Integrated Security=True;User Instance=True"
    Dim con As SqlConnection = New SqlConnection(connString)

    Dim cmdQuery As String = "SELECT * FROM eventinfo WHERE eventID = '" + eventID + "'"
    Dim cmd As SqlCommand = New SqlCommand(cmdQuery)
    Dim myReader As SqlDataReader


    cmd.Connection = con
    cmd.CommandType = CommandType.Text
    con.Open()

    myReader = cmd.ExecuteReader()

    While myReader.Read()

        Label1.Text = myReader("totalDay").ToString()

    End While

    myReader.Close()

    cmd.ExecuteNonQuery()
    cmd.Parameters.Clear()
    con.Close()

    If Label1.Text = "7" Then
        cbWeek1.Enabled = True
        cbWeek2.Enabled = False
        cbWeek3.Enabled = False
        cbWeek4.Enabled = False
        cbWeek5.Enabled = False
        cbWeek6.Enabled = False
        cbWeek7.Enabled = False
        cbWeek8.Enabled = False

    ElseIf Label1.Text = "14" Then

        cbWeek1.Enabled = True
        cbWeek2.Enabled = True
        cbWeek3.Enabled = False
        cbWeek4.Enabled = False
        cbWeek5.Enabled = False
        cbWeek6.Enabled = False
        cbWeek7.Enabled = False
        cbWeek8.Enabled = False

    End If


End Sub


Protected Sub ButtonAddNewBooth_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonAddNewBooth.Click



    Dim connString As String = ConfigurationManager.ConnectionStrings("ConnectionString1").ConnectionString
    '"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\eventdb.mdf;Integrated Security=True;User Instance=True"
    Dim con As SqlConnection = New SqlConnection(connString)


    Dim cmdQuery As String = "INSERT INTO booth(eventID,boothAlias,boothType,week1,week2,week3,week4,week5,week6,week7,week8) VALUES (@eventID,@boothAlias,@boothType,@week1,@week2,@week3,@week4,@week5,@week6,@week7,@week8)"

    Dim cmd = New SqlCommand(cmdQuery)
    cmd.Connection = con
    cmd.CommandType = CommandType.Text
    con.Open()
    cmd.Parameters.AddWithValue("@eventID", ddlEventTitle.SelectedValue)
    cmd.Parameters.AddWithValue("@boothAlias", txtBoothAlias.Text)
    cmd.Parameters.AddWithValue("@boothType", ddlBoothType.SelectedValue)



    If (cbWeek1.Checked = True) Then
        cmd.Parameters.AddWithValue("@week1", "1")
    Else
        cmd.Parameters.AddWithValue("@week1", "0")
    End If

    If (cbWeek2.Checked = True) Then
        cmd.Parameters.AddWithValue("@week2", "1")
    Else
        cmd.Parameters.AddWithValue("@week2", "0")
    End If

    If (cbWeek3.Checked = True) Then
        cmd.Parameters.AddWithValue("@week3", "1")
    Else
        cmd.Parameters.AddWithValue("@week3", "0")
    End If

    If (cbWeek4.Checked = True) Then
        cmd.Parameters.AddWithValue("@week4", "1")
    Else
        cmd.Parameters.AddWithValue("@week4", "0")
    End If

    If (cbWeek5.Checked = True) Then
        cmd.Parameters.AddWithValue("@week5", "1")
    Else
        cmd.Parameters.AddWithValue("@week5", "0")
    End If

    If (cbWeek6.Checked = True) Then
        cmd.Parameters.AddWithValue("@week6", "1")
    Else
        cmd.Parameters.AddWithValue("@week6", "0")
    End If

    If (cbWeek7.Checked = True) Then
        cmd.Parameters.AddWithValue("@week7", "1")
    Else
        cmd.Parameters.AddWithValue("@week7", "0")
    End If

    If (cbWeek8.Checked = True) Then
        cmd.Parameters.AddWithValue("@week8", "1")
    Else
        cmd.Parameters.AddWithValue("@week8", "0")
    End If


    GridViewBoothAdded.DataBind()

    cmd.ExecuteNonQuery()
    cmd.Parameters.Clear()
    con.Close()





End Sub

End Class
  • 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-04T12:10:57+00:00Added an answer on June 4, 2026 at 12:10 pm

    I am not a fan of writing code like this. Personally i do not like keeping my database related info and queries in an aspx file. I would move that code to a function in codebehind file.

    So i will update my UI (.aspx file) like this. Just simple Dropdown list declaration

    <asp:DropDownList ID="ddlEventTitle" runat="server"></asp:DropDownList>
    

    And in your code behind, write a method like this

    Private Sub LoadEvents()
    
        Dim cmdString As String = "SELECT DISTINCT eventID, eventTitle FROM eventinfo"
        Dim connStr As String = "Data Source=Localhost\SQLEXPRESS;Initial Catalog=Flash2;Integrated Security=True;"
        Using conn As New SqlConnection(connStr)
            conn.Open()
            Using cmd As New SqlCommand(cmdString, conn)
                Dim rdr As SqlDataReader = cmd.ExecuteReader()
                ddlEventTitle.DataValueField = "eventID"
                ddlEventTitle.DataTextField = "eventTitle"
                ddlEventTitle.DataSource = rdr
                ddlEventTitle.DataBind()
                ddlEventTitle.Items.Insert(0, New ListItem("Select Event", "0"))
            End Using
        End Using
    
    End Sub
    

    Now call this method in the page load event

    Protected Sub Page_Load(sender As Object, e As EventArgs)
        If Not IsPostBack Then
            LoadFromDataReader()
        End If
    End Sub
    

    This should bring you the Dropdown list with Events with a first element “Select Event” with value “0”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want make interactive application where user launches it and can do various task
I have link for example domain.com/de/controler/action?param=value and I want make actionlink to keep same
I have a situation when I want to change the selected value of a
I have a asp:dropdownlist, which shows below code when page renders <select id=ContactUs_ddlWhichProgrammes name=ContactUs$ddlWhichProgrammes>
I want to specify a value for each option in the my select list
I need a dropdown list on my page that will allow a user to
i have a dropdownlist on the page, now when user does not selects anything
What I want to do is make a dropdownlist choices change depending on other
I just want to send the value of my dropdownlist with a requestparameter. In
I want make datetimepicker in my project. Using jquery how it is possible? I

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.