Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table in database. i have binded to gridview using dataadapter and dataset. I want to find particular record in dataset. After finiding that record i want to bind it to another gridview.

please help me thank you.
Posted

Hi,
Hope it help you .
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);
        }
        GridView1.DataSource = dt; 
        GridView1.DataBind();
    }


ASP.NET
<div>
       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true">
       </asp:GridView>
   </div>

Best Regards
M.Mitwalli
 
Share this answer
 
Hi,

It Would be Better if you use Dataview and filter the Row as :


C#
DataView dvwData = new DataView(ds.Tables[0]);
dvwData.RowFilter = "";
dvwData.RowFilter = "PrimaryKey = '" + PrimaryKeyValue + "'";


Here ds is Your Dataset
Now you can bind your second gridView with dvwData as DataSource..

Hope This May Help You...
 
Share this answer
 
The current cell value can be retrieved using the SelectedItem property of DataGrid as explained here.
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.selecteditem(v=vs.95).aspx#Y600[^]
then DataRows can be retrieved from the DataTable of DataSet using Select method of DataTable as explained here
http://msdn.microsoft.com/en-us/library/b5c0xc84.aspx[^]
 
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