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?
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();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
-saige-