Link to home
Start Free TrialLog in
Avatar of RecipeDan
RecipeDan

asked on

SelectedIndexChanged Clear previous value

I have a asp:ListBox with a SelectedIndexChanged that fires. When I click it once it shows a value; however when I click another item that value shows as well as the first value. How can I clear the first value when I click on the listbox again?
Avatar of it_saige
it_saige
Flag of United States of America image

Please provide the code for your SelectedIndexChanged method.

-saige-
Avatar of RecipeDan
RecipeDan

ASKER

        protected void PersonList_SelectedIndexChanged(object sender, EventArgs e)
            {
                ListBox list = (ListBox)sender;
                SqlConnection conn;
                SqlCommand comm;
                SqlDataReader reader;
                string connectionString = ConfigurationManager.ConnectionStrings["DConn"].ConnectionString;
                conn = new SqlConnection(connectionString);
                comm = new SqlCommand("SELECT IntNum, FullName, SSN FROM TestNames WHERE IntNum = @ListID", conn);
                comm.Parameters.Add("@ListID", System.Data.SqlDbType.Int);
                comm.Parameters["@ListID"].Value = list.SelectedValue;
                try
                {
                    conn.Open();
                    reader = comm.ExecuteReader();
                    while (reader.Read()) 
                    { 
                        label1.Text += reader["FullName"] + "<br />";
                        label2.Text += reader["SSN"] + "<br />"; 
                    } 
                    reader.Close();
                }
                finally
                {
                    conn.Close();
                }    
            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial