User-1838255255 posted
Hi asp.ambur,
According to your description and needs, I use datatable to replace the database, for more details, please check the following sample code:
<body>
<form id="form1" runat="server">
<div>
<span>Table A</span>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="ItemName" HeaderText="ItemName" ItemStyle-Width="150" />
<asp:BoundField DataField="Qty" HeaderText="Qty" ItemStyle-Width="150" />
<asp:BoundField DataField="BelongsTo" HeaderText="BelongsTo" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
<span>Table B</span>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="ItemName" HeaderText="ItemName" ItemStyle-Width="150" />
<asp:BoundField DataField="Qty" HeaderText="Qty" ItemStyle-Width="150" />
<asp:BoundField DataField="BelongsTo" HeaderText="BelongsTo" ItemStyle-Width="150" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
dt.Columns.Add("ItemName", typeof(string));
dt.Columns.Add("Qty", typeof(string));
dt.Columns.Add("BelongsTo", typeof(string));
dt.Rows.Add("Apple", "5", "A");
dt.Rows.Add("Mango", "4", "C");
dt.Rows.Add("Orange", "2", "D");
binddata();
}
public void binddata()
{
GridView1.DataSource = dt;
GridView1.DataBind();
DataRow[] result = dt.Select("BelongsTo= 'A'");
DataTable table = new DataTable();
table.Columns.Add("ItemName", typeof(string));
table.Columns.Add("Qty", typeof(string));
table.Columns.Add("BelongsTo", typeof(string));
foreach (DataRow row in result)
{
table.Rows.Add(row[0],row[1],row[2]);
}
GridView2.DataSource = table;
GridView2.DataBind();
}
Result:
Best Regards,
Eric Du