how to bind data of selected item in listbox to different controls of form
hello, I am developing a ado.net windows app with c# and sql 2005. I have 1 listbox. Listbox is bound to the tour table of database. On click event of 'Edit' button a dilogue box opens with controls such as tour name,min people,max people,unit price etc. It should contain specific information related to the tour name which is selected in listbox. I tried to bind the dilogue box with database. But it shows only first row of table. Please help...
Subhendu DePosted Jul 3, 2011, 2:49 PM
When you select tour from listbox and select edit button, a new dialog box open. Since you are using windows app, you must use like
Form1 frm = new Form1();
frm.Show();
I would suggest you to pass the tour id information in Form1 constructor and read the database value again in Form1 like
Form1 frm = new Form1(listbox1.SelectedValue);
frm.Show();
Truly speaking, this is not a good option because it would increase the database hits more. So you can concatenate all the information in a string separated by some special characters and pass it in Form1 constructor so that you can retrieve it in the Form1.
Sam HobbsPosted Jul 3, 2011, 2:23 PM
Vilas GitePosted Jul 3, 2011, 3:14 AM
please see control databind in zip and sql database and table here
//
create database tour
use tour
create table tourtbl
(
tour_name varchar(50),
min_people varchar(10),
max_people varchar(10),
unit_price numeric(8,2)
)
select * from tourtbl
//
----------------------------------------------------------------------------------------------------
If this reply hepls your post…then "MARK AS ANSWER"!