Click here to Skip to main content
14,271,826 members
Rate this:
Please Sign up or sign in to vote.
See more:
i want to filter the data in dataset and that data display in gridview.
Posted
Updated 29-Mar-12 21:44pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi , Try this
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();
   }
   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,

just Search It On Google[]

U Will Get Ton Of Results.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

I think these Code Project articles may be helpful

Custom GridView with Paging and Filtering[^]
GridView all in one[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

try this it may help you

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
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 6

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[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 7

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
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100