Click here to Skip to main content
15,907,905 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I have a gridview and a listbox.Now I want to filter the data of column "symbol" from listbox which has a list of symbols.Dataview is not working because each time it
replaces the previous row of gridview.
Posted
Comments
R. Giskard Reventlov 25-Dec-11 4:38am    
The question makes no sense: please rephrase more clearly.

public void datafetch_of_currdate() //1ST FUNCTION...............................................................................
{
if (this.Page.IsPostBack == false)
{
DataSet ds = new DataSet();
da = new OleDbDataAdapter("select sr_no,call_time,b_s,symbol,entry,exit_sl,exit_target,instrument,curr_status,call_type from emp where curr_date=#" + DateTime.Now.ToShortDateString() + "# order by sr_no desc", cn);
da.Fill(ds, "table");
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
ds.Tables[0].Rows.Clear();
for (int i = 0; i < ListBox1.Items.Count; i++)
{
foreach (GridViewRow gr in GridView1.Rows)
{
if (gr.Cells[3].Text == ListBox1.Items[i].Text)
{

DataRow dr = ds.Tables[0].NewRow();
dr["sr_no"] = gr.Cells[0].Text;
dr["call_time"] = gr.Cells[1].Text;
dr["b_s"] = gr.Cells[2].Text;
dr["symbol"] = gr.Cells[3].Text;
dr["entry"] = gr.Cells[4].Text;
dr["exit_sl"] = gr.Cells[5].Text;
dr["exit_target"] = gr.Cells[6].Text;
dr["instrument"] = gr.Cells[7].Text;
dr["curr_status"] = gr.Cells[8].Text;
dr["call_type"] = gr.Cells[9].Text;

ds.Tables[0].Rows.Add(dr);


}

}
}

GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}

}



call this function in form load event.
 
Share this answer
 
you can try below code :

 DataSet ds = new DataSet();
 DataTable dt;
 DataTable dtnew;

 OleDbDataAdapter da = new OleDbDataAdapter("Your query", "connection Object");
 da.Fill(ds, "table");
 string strfilterexpretion="";
 // Write a code for get filer expretion like below example
 foreach(ListItem lsitem in ListBox1.Items)
 {
     if(lsitem.Selected )
     {
         if(strfilterexpretion ==string.Empty)
         {

         strfilterexpretion +="'"+lsitem.Text+"'";
         }
         else
         {
         strfilterexpretion +=",'"+lsitem.Text+"'";
         }
     }
}

 // you get selected Row only.
 DataRow[] drs = dt.Select("symbole in (" + strfilterexpretion +")";

 // Create a new table
 dtnew.Rows.Add(drs);

 // Bind the grid view
 GridView1.DataSource = dtnew;
 GridView1.DataBind();



Let me know if it is helpfull to you or not.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900