data grid or any other solution

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top