1 Replies - 8420 Views - Last Post: 24 July 2012 - 03:34 PM Rate Topic: -----

#1 ppdeepu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-July 12

How to bind Gridview using verifying listbox multiple selected value

Posted 24 July 2012 - 12:46 AM

I have Listbox in which I have bind this listbox with the data from table which are(Bracnh List) Like Delhi, Mumbai, Kolkata. Branches in listbox. Therefor I want to fetch data from table where listbox.item.selected value matched into the table. User make selection multiple. User Selects Multiple branches so there will be loop as many as user make selection in listbox. Then data will come from table according to selection made.
In first loop I get data from table and bind it to gridvew. But in second loop dataset get orverwrite. Therefore it show only one row data. I mean If user select three branched loop will go to three time and there will be three row in gridview. How to do it.
Thanks
public void MyDetailandSum()
        {
    
  if (ListBoxFrom.Items.Count > 0)

                {
                    DataTable dt = new DataTable();
                    DataSet ds = new DataSet();
                    for (int i = 0; i < ListBoxFrom.Items.Count; i++)
                    {

                        if (ListBoxFrom.Items[i].Selected)
                        {
                          
                            con = new SqlConnection(Constr);
                            string Listbfrom = ListBoxFrom.Items[i].Text;
                            
                            con.Open();
                            string str = "select  CODE_NAME, count(CODE_NAME) AS TOTCNMT,sum(FREIGHT) AS FREIGHT,SUM(RC)AS RC,SUM(CARTRAGE)AS CARTRIDGE,SUM(OSC)AS OSC,SUM(HAMALI) AS HAMALI,SUM(OTHER)AS OTHER,SUM(INSURANCE) AS INSURANCE,SUM(BILTYCHARGE) AS BC,SUM(SC) AS SC, SUM(PF)AS PF,SUM(CLAIM)AS CLAIM, sum(TOTAL) AS TOTAL, SUM(STAX) AS TAX,sum(GTOTAL)AS GTOTAL from Consignment  where CODE_NAME='" + Listbfrom + "'group by CODE_NAME";
                            SqlCommand com = new SqlCommand(str, con);
                            DataSet dsBooking = new DataSet();
                            SqlDataAdapter dap = new SqlDataAdapter(com);
                            dap.Fill(dsBooking, "Booking");
                            
                            
                            GrvEnquiry.DataSource = dsBooking;
                            GrvEnquiry.DataBind();

                        }
                    }
                }
    }

This post has been edited by Atli: 24 July 2012 - 12:49 AM
Reason for edit:: Please use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: How to bind Gridview using verifying listbox multiple selected value

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 444
  • View blog
  • Posts: 1,492
  • Joined: 28-April 09

Re: How to bind Gridview using verifying listbox multiple selected value

Posted 24 July 2012 - 03:34 PM

You need to get all of the selected values and put them in a comma separated string. Then change your where statement to be "where CODE_NAME IN (your, list, of, values)'
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1