i am using C#,asp.net and sql server 2005.
now i want to show the value of one column in listbox during page load.
i did as follow:this code displays me correctly the value on list box.Code:string sqlvisa = "select visano from saudivisatbl"; con.Open(); SqlCommand sqlquery = new SqlCommand(); DataTable data = null; sqlquery.Connection = null; SqlDataAdapter ddapter = null; sqlquery.CommandText = sqlvisa; sqlquery.Connection = con; data = new DataTable(); ddapter = new SqlDataAdapter(sqlquery); ddapter.Fill(data); for (int i = 0; i < data.Rows.Count; i++) { string data1 = data.Rows[i]["visano"].ToString(); listboxvisa.Items.Add(data1); } con.Close();
now i want to assign the value of the selected value in the listbox into textbox1 on button click
again the the value of the selected list box item is dispayed in the textbox1 on btn click, but the value of the listboxvisa becomes duplicated, when i click the button then again it will duplicate,Code:protected void btnselectvalue_Click(object sender, EventArgs e) { textbox1.Text = listboxvisa.SelectedItem.ToString(); }
how do i prevent this duplication of on button click.
thanks




Reply With Quote