We help IT Professionals succeed at work.
Get Started

Problem with dropdown after binding arraylist

454 Views
Last Modified: 2012-07-09
Hi folks.  I have a dropdown that I have successfully bound to arraylist.  My problem is that when I select an option, my insert statement is showing there is no value selected.  I am querying a table for the ratings that are to populate the dropdown.  The result is a string list, so I am interating thru the list to populate the arralylist, then binding to the dropdown. Please advise.  My code is below:


bool bIsError = false;
            alRatings = new ArrayList(1); // create arraylist to hold Possible Rating Responses
            alRatings.Add("");
            SqlConnection con = new SqlConnection(strConnection);
             string tempOption = "";
            try
            {
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "SELECT DISTINCT FormatType FROM t_Questions Where FormName= '" + formFilter + "' AND SeqNumber= " + tempSeqNum;
                con.Open();
                SqlDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        tempOption = dr["FormatType"].ToString();
                       
                    }
                 
                   
                    string[] strtemp = tempOption.Split(';');
                        foreach (string s in strtemp)
                        {
                            alRatings.Add(s);
                        }
                        alRatings.TrimToSize();
                    Rating.DataSource = alRatings;
                    Rating.DataBind();
                    con.Close();
                }
                else
                {
                    ........
                }
            }
            catch (Exception err)
            {.....
          }

INSERT Statement:

cmdInsert2.CommandText = "INSERT INTO t_Answers(CNTRL_NUM, Date, User, SeqNumber, " +
                        " Response, Comment)  VALUES( '" + CNTRL_NUM.Text + "', '" + Date.Text + "', '" + User.Text + "', " + SeqNumber.Text + ", '" + Rating.SelectedValue + "', '" + txtCmt.Text + "' );";
Comment
Watch Question
IT Analyst
Top Expert 2012
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE