Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. list box

list box

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Siva Myneni
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • S Siva Myneni

      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

      A Offline
      A Offline
      Aslam Bari
      wrote on last edited by
      #2

      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.

      S 1 Reply Last reply
      0
      • A Aslam Bari

        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.

        S Offline
        S Offline
        Siva Myneni
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • S Siva Myneni

          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

          A Offline
          A Offline
          Aslam Bari
          wrote on last edited by
          #4

          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]]); }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups