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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:40:46+00:00 2026-05-25T21:40:46+00:00

I have a dropdown list that will add new titles to my database, however

  • 0

I have a dropdown list that will add new titles to my database, however I would like to add a textbox that will allow the user to type in a new title if there is nothing in the dropdown that makes any sense for what they are trying to add.

I have the dropdown dynamically getting titles from the database. Unfortunately, this means that the first value in the dropdown list is not a default that says “Select an option.” I don’t know how to get the dropdown to have the first option listed as “Select” when the values are being pulled from the database. I can’t add Select an option to the database so how would this even work?

What can I add to my codebehind that will allow the textbox to insert into the database if the dropdown list is not inserting anything? Right now I don’t have any codebehind for the textbox but I do have the dropdown list inserting the correct information.

<li class="alternatingItem">
<asp:LinkButton ID="DescButton" runat="server">Description</asp:LinkButton>
  <asp:Panel ID="DescPanel" runat="server" CssClass="modalPopup" Style="display:none">
  <div class="PopupHeader">Add a Description</div>
  Title:<asp:DropDownList ID="ddlDescription" runat="server" DataSourceID="dsNewDescription" DataTextField="Title" DataValueField="Title">
  </asp:DropDownList><br />
  New Title:<asp:TextBox ID="NewDescTitle" runat="server"></asp:TextBox><br />
  Description:<asp:TextBox ID="Description" runat="server" TextMode="MultiLine">
  </asp:TextBox><br />
  <asp:Button ID="submitDescription" runat="server" Text="Submit" />
  <asp:Button ID="CancelSubmitDesc" runat="server" Text="Cancel" />
  </asp:Panel>
    <asp:ModalPopupExtender ID="DescModal" runat="server" DropShadow="True" 
    DynamicServicePath="" Enabled="True" PopupControlID="DescPanel"
    TargetControlID="DescButton">
    </asp:ModalPopupExtender>
    </li>




Protected Sub submitDescription_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles submitDescription.Click
    DescModal.Hide()

    'SQL INSERT: Marketing Table
    Dim strSQL As String = "INSERT INTO Picklist (Title, Data) 
    VALUES (@Title, @Data);
    INSERT INTO Marketing
    (ProductID, MarketingTypeID, MarketingTitle, MarketingData) 
    VALUES (@ProductID ,2, 'Description', scope_identity())"
    Using cn As New SqlConnection
    (System.Configuration.ConfigurationManager.ConnectionStrings
    ("LocalSqlServer").ConnectionString)
        Using cmd As New SqlCommand(strSQL, cn)
            cmd.Parameters.Add(New SqlParameter("@Title", 
            ddlDescription.SelectedValue))
            cmd.Parameters.Add(New SqlParameter("@Data", 
            Description.Text))
            cmd.Parameters.Add(New SqlParameter("@ProductID",
            ProductID.Value))

            cn.Open()

            cmd.ExecuteNonQuery()
        End Using
    End Using
    Response.Redirect(Request.RawUrl)
End Sub

WORKING CODE

Title:<asp:DropDownList ID="ddlDescription" runat="server"
DataSourceID="dsNewDescription" DataTextField="Title" DataValueField="Title" 
enableViewstate="False" AutoPostBack="True" AppendDataBoundItems="True">
<asp:ListItem Text="Select below or enter new" Selected="True"></asp:ListItem>

 If ddlDescription.SelectedValue <> "Select below or enter new" Then
    cmd.Parameters.Add(New SqlParameter("@Title", ddlDescription.SelectedValue))
 Else
    cmd.Parameters.Add(New SqlParameter("@Title", NewDescTitle.Text))
 End If
  • 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-05-25T21:40:47+00:00Added an answer on May 25, 2026 at 9:40 pm

    You can try something like this:

    <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" onblur="validateSelection(this)" ...>
        <asp:ListItem Text="" Value="" />
    </asp:DropDownList>
    <asp:TextBox ID="TextBox1" runat="server" style="display:none;"  ... />
    

    Your JavaScript function (not positive, but it should be close):

    validateSelection = function(selectList){
        var input = document.getElementById("<%=TextBox1.ClientID%>");
        if (input){
            input.style.display = selectList.selectedIndex > -1 ? "block" : "none";
            if (selectList.selectedIndex > -1){
                input.focus();
            }            
        }
    }
    

    And in your code-behind:

    string description = TextBox1.Text;
    if (!String.IsNullOrEmpty(DropDownList1.SelectedValue))
        description = DropDownList1.SelectedValue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dropdown list that stores name/value pairs. The dropdown appears in each
I have a dropdown list with a piece of code that is run when
I'm using classic asp, I have a drop down list that the user selects
i have a dropdownlist that populates from the sql server database. populating the list
I have a table that will rebuild async every time a new option is
I have a simple form that has a list (dropdown list generated from a
I have a drop down list that has options that need to be passed
I have a drop down list that triggers an updatepanel when the index is
I have about 10 drop down list controls that get populated. Instead of copying/pasting
I have written a cascading drop down list using JQuery. The code that 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.