list box
-
i have two tables one is class table,student table if i select a class from class table all the students presnt in that class should be added to list box if i select two classes all the students present in the two classes will have to come into the list box but i am getting only the last one of the class can anybody help me please? :) sivamyneni
-
i have two tables one is class table,student table if i select a class from class table all the students presnt in that class should be added to list box if i select two classes all the students present in the two classes will have to come into the list box but i am getting only the last one of the class can anybody help me please? :) sivamyneni
Hi sivamyneni, I think when you select one class , the result come in the list box. but when you select the second class , the previos result disappear and the new one shows. I am not sure what method you are using for adding in the list box. Before adding items in the list box , be sure, you should not clear the list. You have to append or insert into the list. If problem not solved, than show the code to me.
-
Hi sivamyneni, I think when you select one class , the result come in the list box. but when you select the second class , the previos result disappear and the new one shows. I am not sure what method you are using for adding in the list box. Before adding items in the list box , be sure, you should not clear the list. You have to append or insert into the list. If problem not solved, than show the code to me.
Hi Aslam Bari, I just want to find out how to append the items into the list this is the code i used in my project // foreach(DataGridItem di in DataGrid1.Items) { CheckBox check=(CheckBox)(di.Cells[0].FindControl("checkbox")); if(check.Checked==true) { // here retrieving the items from database to the dataset after that just wrote this code Dataset dsItem=new DataSet(); ListBox1.DataSource=dsItem; ListBox1.DataBind(); ListBox1.DataTextField=dsItem.Tables[0].Columns["ThumbNail"].ToString(); Thanks in advance sivamyneni
-
Hi Aslam Bari, I just want to find out how to append the items into the list this is the code i used in my project // foreach(DataGridItem di in DataGrid1.Items) { CheckBox check=(CheckBox)(di.Cells[0].FindControl("checkbox")); if(check.Checked==true) { // here retrieving the items from database to the dataset after that just wrote this code Dataset dsItem=new DataSet(); ListBox1.DataSource=dsItem; ListBox1.DataBind(); ListBox1.DataTextField=dsItem.Tables[0].Columns["ThumbNail"].ToString(); Thanks in advance sivamyneni
Dear Sivamyneni, Currently i don't know the problem with DataSource, i think at a time we can add only one datasource. I also couldn't find the listbox.DataBind() and listbox.DataTextField. What version of .NET u r using. By the Way an alternate way i am giving here and try it.. //Connection to database OdbcConnection con = new OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};server=localhost;database=mysql;uid=root;pwd=mysql"); con.Open(); //Get data from user table OdbcDataAdapter ad = new OdbcDataAdapter("select * from user", con); DataSet set = new DataSet(); ad.Fill(set); //Here is the code to add all the items of the first column of the user table. foreach (DataRow row in set.Tables[0].Rows) { listBox1.Items.Add(row[set.Tables[0].Columns[0]]); } ////ON OTHER EVENT LIKE CHECKBOX OR BUTTON CLICK REPEAT THIS. OdbcDataAdapter ad = new OdbcDataAdapter("select * from BILL", con); DataSet set = new DataSet(); ad.Fill(set); //Here is the code to add all the items of the first column of the bill table. foreach (DataRow row in set.Tables[0].Rows) { listBox1.Items.Add(row[set.Tables[0].Columns[0]]); }