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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:44:52+00:00 2026-05-14T08:44:52+00:00

Basically I have a drop down list which is populated with text and values

  • 0

Basically I have a drop down list which is populated with text and values depending on a selected index of a radio button list. The code is as follows:

protected void RBLGender_SelectedIndexChanged(object sender, EventArgs e)
    {
        DDLTrous.Items.Clear();
        DDLShoes.Items.Clear();
        if (RBLGender.SelectedValue.Equals("Male"))
        {

            String[] MaleTrouserText = {"[N/A]", "28\"", "30\"", "32\"", "34\"", "36\"", "38\"", "40\"", "42\"", "44\"", "48\""};
            String[] MaleTrouserValue = { null, "28\"", "30\"", "32\"", "34\"", "36\"", "38\"", "40\"", "42\"", "44\"", "48\"" };
            String[] MaleShoeText = { "[N/A]", "38M", "39M", "40M", "41M", "42M", "43M", "44M", "45M", "46M", "47M" };
            String[] MaleShoeValue = { null, "38M", "39M", "40M", "41M", "42M", "43M", "44M", "45M", "46M", "47M" };
            for (int i = 0; i < MaleTrouserText.Length; i++)
            {
                ListItem MaleList = new ListItem(MaleTrouserText[i], MaleTrouserValue[i]);
                DDLTrous.Items.Add(MaleList);

            }
            for (int i = 0; i < MaleShoeText.Length; i++)
            {
                ListItem MaleShoeList = new ListItem(MaleShoeText[i], MaleShoeValue[i]);
                DDLShoes.Items.Add(MaleShoeList);

            }

        }

            else if (RBLGender.SelectedValue.Equals("Female"))`

When the text ‘[N/A]’ is selected I want the value NULL to be inserted into the database. At present when ‘[N/A]’ is selected the value entered into the database is [N/A] does anyone know why?

This is my DB insertion code:

protected void UpdateWorkWear()
    {



        try
        {

            string connectionString = Common.GetConnectionString("w34to4tmConnectionString");

            SqlConnection conn = new SqlConnection(connectionString);

            StringBuilder sbSQL = new StringBuilder();


            string str = DDLSurname.SelectedValue;

            if (str.Contains("'"))
            {
                str = str.Replace("'", " ");

            }

            sbSQL.Append("IF EXISTS (select * from TO4_WORKWEAR_DISTRIBUTION where EmpID = @EmpID)");
            sbSQL.Append(" UPDATE TO4_WORKWEAR_DISTRIBUTION SET ");
            sbSQL.Append("costCentre = coalesce(@Cost_Centre, CostCentre), EmployeeType = coalesce(@EmployeeType, EmployeeType), Initials = coalesce(@Initials, Initials), Surname = coalesce(@Surname, Surname), ");
            sbSQL.Append("IssueQuarter = coalesce(@IssueQuarter, IssueQuarter), TrouserSize = coalesce(@Trouser_S, TrouserSize), TrouserLength = coalesce(@Trouser_L, TrouserLength), ");
            sbSQL.Append("PoloSize = coalesce(@Polo_S, PoloSize),  SweatSize = coalesce(@Sweat_S,SweatSize), ShortSize = coalesce(@Short_S, ShortSize), ShoeSize = coalesce(@Shoe_S, ShoeSize) WHERE EmpID = @EmpID ");
            sbSQL.Append(" else INSERT INTO TO4_WORKWEAR_DISTRIBUTION (EmpID,CostCentre, EmployeeType, Initials, Surname, IssueQuarter, TrouserSize, TrouserLength, PoloSize, SweatSize, ShortSize, ShoeSize) ");
            sbSQL.Append("VALUES (@EmpID, @Cost_Centre, @EmployeeType, @Initials, @Surname, @IssueQuarter, @Trouser_S, @Trouser_L, @Polo_S, @Sweat_S, @Short_S, @Shoe_S)");




            sbSQL.Replace("@EmpID", "'" + DDLEmpID.SelectedValue + "'");
            sbSQL.Replace("@Cost_Centre", "'" + DDLCostCentre.SelectedValue + "'");
            sbSQL.Replace("@EmployeeType", "'" + RBLAssociate.SelectedValue + "'");
            sbSQL.Replace("@Initials", "'" + DDLInitials.SelectedValue + "'");
            sbSQL.Replace("@Surname", "'" + str + "'");
            sbSQL.Replace("@Trouser_S", "'" + DDLTrous.SelectedValue + "'");
            sbSQL.Replace("@Trouser_L", "'" + DDLTrouserLnh.SelectedValue + "'");
            sbSQL.Replace("@Trouser_Q", "'" + DDLTrouserQty.SelectedValue + "'");
            sbSQL.Replace("@Polo_S", "'" + DDLPolo.SelectedValue + "'");
            sbSQL.Replace("@Polo_Q", "'" + DDLPoloQty.SelectedValue + "'");
            sbSQL.Replace("@Sweat_S", "'" + DDLSweat.SelectedValue + "'");
            sbSQL.Replace("@Sweat_Q", "'" + DDLSweatQty.SelectedValue + "'");
            sbSQL.Replace("@Shoe_S", "'" + DDLShoes.SelectedValue + "'");
            sbSQL.Replace("@Short_S", "'" + DDLShor.SelectedValue + "'");
            sbSQL.Replace("@InputDate", "'" + System.DateTime.Now.Date.ToString("MM/dd/yyyy") + "'");
            sbSQL.Replace("@IssueQuarter", "'" + RBLQuarter.SelectedValue + "'");

            SqlCommand cmd = new SqlCommand(sbSQL.ToString(), conn);
            cmd.CommandType = CommandType.Text;

            conn.Open();

            int result = cmd.ExecuteNonQuery(); //execute the SQL command on the database   
            LiteralControl lit = new LiteralControl();
            lit.Text = String.Format("Data Uploaded Successfully.");

Thanks for all your help guys.
I have decided to insert blank strings “” into the datbase instead of null now as it makes my life slightly easier when i run reports from it.

  • 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-14T08:44:52+00:00Added an answer on May 14, 2026 at 8:44 am

    The problem is that if a ListItem has its value set to null, it will use the Text property as the value. For example this code:

    ListItem l = new ListItem("Cats", null);
    
    string s = l.Value;
    

    The value of s is “Cats”.

    The solution is not to store null, but store an empty string, or -1, or something similar, and then check for this in your code.

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

Sidebar

Ask A Question

Stats

  • Questions 404k
  • Answers 405k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, Drupal uses a lot of Database. However, you can… May 15, 2026 at 5:39 am
  • Editorial Team
    Editorial Team added an answer I found the answer on another forum. You have to… May 15, 2026 at 5:39 am
  • Editorial Team
    Editorial Team added an answer Finally I found the reason for the exception. The problem… May 15, 2026 at 5:39 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.