I am developing an application in windows forms
I have two grids (grid1 and grid2)
I have a textbox and two buttons (search and group).
By clicking on the search button I do a search according to the entry in the textbox,
and the result is assigned to a DataTable to then display it in the first grid.
My question is how do I make each search result is displayed in the second grid without losing the data?
ie to accumulate in the second grid
Loading
Syed ShakeerPosted Jan 20, 2011, 12:44 PM
Suppose you have a Data in a First Grid DataTable
DataTabale dt1=new DataTable();
:
:
GridView1.DataSource=dt;
GridView1.DataBind();
Adding First Grid data(dataTable dt1) in another table.
By using NewRow()
DataTable dt2=new DataTable();
for(int i=0;i
{
DataRow dr2=dt2. DataRw();
dr2[0]=dt1.Rows[i][0].ToString();
dr2[1]=dt1.Rows[i][1].ToString();
dt2.Rows.Add(dr2);
}
GridView2.DataSource=dt2;
Gridview2.DataBind();
Note:-Create the DataTable dt2 object as Publci.Declare it in Public location.
hugo sanchezPosted Jan 20, 2011, 11:30 AM
Yes that's what I mean
For exemple:
By the first clicking on the search button By the second clicking on the search button
Grid1 Grid1
id name id name
1 hugh 3 richard
2 michael 5 rose
by the first clicking on the group button by the second clicking on the group button and so on
Grid2 Grid2
id name id name
1 hugh 1 hugh
2 michael 2 michael
3 richard
5 rose
Raghvendr SinghPosted Jan 20, 2011, 1:59 AM
public static DataTable MyTable;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
MyTable = new DataTable();
MyTable = createDT();
}
}
protected DataTable createDT()
{
//you may create multiple columns as per your requirement
DataTable dt = new DataTable();
DataColumn DC0 = new DataColumn("SearchResult");
dt.Columns.Add(DC0);
return dt;
}
protected void btnSearch_Click(object sender, EventArgs e)
{
//Write code for searching
DataRow drw = MyTable.NewRow();
drw[0] = "Your Search result";
MyTable.Rows.Add(drw);
GridView2.DataSource = MyTable;
GridView2.DataBind();
}
Syed ShakeerPosted Jan 20, 2011, 1:34 AM
You mean you want to add Grid1 dataTable to Grid2.And Grid2 data not to change.
Only Grid1 DataTabel have to change..