D
Dag Johansen
Hi,
instead of creating a view you can execute two selects,
selecting the appropriate records from the two tables.
This can be done in one trip to the db, e.g. "select *
from employee; select * from salary" results in a dataset
with two tables. This also removes redundancy, reducing
data transfer and gaining performance.
Now you can bind one grid or other UI elements to the
employee table (or a dataview based on that table), and a
second grid to the salary table's defaultview. Whenever
the user selects an employee in the first grid, update the
filter on the salary dataview and rebind the grid - voila.
Example assuming you have the ID of the selected employee
in a variable named empID:
DataView dv = myDataSet.Tables[1].DefaultView;
dv.RowFilter = "employeeID=" + empID;
salaryGrid.DataBind();
Two things that should be mentioned:
1. Persistance. You must read all the data from the
backend each webform round-trip, or otherwise persist the
data (e.g. in memory using session state) on the server.
2. Databinding: Although the code over calls databind
after setting the filter, you might want to reconsider. In
a scenario where many events neccesitate rebinding
controls (say you want to change sort order as well as a
filter, both of which require rebinding), you want to
rebind only once - since it is an expensive operation. A
simple way to achieve this is to initialize a
flag "mustRebind" to false when the page is constructed
and raise it whenever you would otherwise call Databind.
Then handle the PreRender event and call Databind if and
only if "mustRebind" is set.
Good luck! Sincerely,
Dag
instead of creating a view you can execute two selects,
selecting the appropriate records from the two tables.
This can be done in one trip to the db, e.g. "select *
from employee; select * from salary" results in a dataset
with two tables. This also removes redundancy, reducing
data transfer and gaining performance.
Now you can bind one grid or other UI elements to the
employee table (or a dataview based on that table), and a
second grid to the salary table's defaultview. Whenever
the user selects an employee in the first grid, update the
filter on the salary dataview and rebind the grid - voila.
Example assuming you have the ID of the selected employee
in a variable named empID:
DataView dv = myDataSet.Tables[1].DefaultView;
dv.RowFilter = "employeeID=" + empID;
salaryGrid.DataBind();
Two things that should be mentioned:
1. Persistance. You must read all the data from the
backend each webform round-trip, or otherwise persist the
data (e.g. in memory using session state) on the server.
2. Databinding: Although the code over calls databind
after setting the filter, you might want to reconsider. In
a scenario where many events neccesitate rebinding
controls (say you want to change sort order as well as a
filter, both of which require rebinding), you want to
rebind only once - since it is an expensive operation. A
simple way to achieve this is to initialize a
flag "mustRebind" to false when the page is constructed
and raise it whenever you would otherwise call Databind.
Then handle the PreRender event and call Databind if and
only if "mustRebind" is set.
Good luck! Sincerely,
Dag