Click here to Skip to main content
15,567,221 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i want to filter the data in dataset and that data display in gridview.
Posted
Updated 29-Mar-12 22:44pm
v2

Hi , Try this
C#
protected void Page_Load(object sender, EventArgs e)
   {
       SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=test;Integrated Security=True");
       string statment = "select item_code, Item_name, brand, size, section, price, Material, Qty, tax, tt  from Items ";
       SqlDataAdapter da = new SqlDataAdapter(statment, con);
       DataSet ds = new DataSet();
       da.Fill(ds);
       DataRow[] foundRows = ds.Tables[0].Select("item_code = 1", " item_code DESC", DataViewRowState.CurrentRows);
       //this is for create datatable with same schema like the orginal one .
       string statment2 = "select item_code, Item_name, brand, size, section, price, Material, Qty, tax, tt  from Items where  item_code = 0";
       SqlDataAdapter da2 = new SqlDataAdapter(statment2, con);
       DataTable dt = new DataTable();

       da2.Fill(dt);
       DataRow dr = dt.NewRow();
       foreach (DataRow row in foundRows)
       {
           dr[0] = row[0];
           dr[1] = row[1];
           dr[2] = row[2];
           dr[3] = row[3];
           dr[4] = row[4];
           dr[5] = row[5];
           dt.Rows.Add(dr);
       }
       con.Close();
       cmd.Dispose();
       GridView1.DataSource = dt;
       GridView1.DataBind();
   }
 
Share this answer
 
v3
Hi,

just Search It On Google[]

U Will Get Ton Of Results.
 
Share this answer
 
I think these Code Project articles may be helpful

Custom GridView with Paging and Filtering[^]
GridView all in one[^]
 
Share this answer
 
try this it may help you

VB
Sub BindData()

       Dim myConnection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= Csharp.xls;Extended Properties=""Excel 12.0 Xml;HDR=YES""")


       Const strSQL As String = "select * from [sheet1$]"
       Dim myCommand As New OleDbCommand(strSQL, myConnection)


       Dim myDataAdapter As New OleDbDataAdapter(myCommand)
       Dim myDataSet As New DataSet()
       myDataAdapter.Fill(myDataSet, "sheet1")
       myConnection.Close()


       Dim myDataTable As DataTable = myDataSet.Tables(0)
       myDataTable.Columns.Add(New DataColumn("RandNum", GetType(Integer)))

       Dim i As Integer
       'Dim divi As Integer
       Dim k As Integer
       Dim rndNum As New Random()
       For i = 0 To myDataTable.Rows.Count - 1
           k = (rndNum.Next(100))
                       myDataTable.Rows(i)("RandNum") = k


           
       Next i

       Dim myDataView As DataView = myDataTable.DefaultView
       myDataView.Sort = "RandNum"

       GridView1.DataSource = myDataView
       GridView1.DataBind()
   End Sub
 
Share this answer
 
v2
filter the data in dataset and that data display in gridview
You can use DataView and it's row filter property.

On the filter event, just filter the data using a dataview and then use the filtered dataview as the datasource of your grid.

To know more of it, read here: MSDN: DataView.RowFilter Property[^]
 
Share this answer
 
hi,

Whatever you awnt to filter in dataset. set it as in where clause of db query after that it set as datasource of gridview

Regards, Saurabh
 
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