Avatar of ptslv
ptslvFlag for United States of America

asked on 

Problem with dropdown after binding arraylist

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 + "' );";
Web Languages and StandardsASP.NET

Avatar of undefined
Last Comment
ptslv
Avatar of ptslv
ptslv
Flag of United States of America image

ASKER

Sorry...I forgot to mention that my first option is empty.  If I remove the empty option, then the very first option is the resulting value regardless of what I select in the dropdown.
ASKER CERTIFIED SOLUTION
Avatar of Roopesh Reddy
Roopesh Reddy
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of ptslv
ptslv
Flag of United States of America image

ASKER

Thank you for the help.  I had moved it out of the (!Page.IsPostBack) and putting it back in there fixed my dropdown.
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo