How do I fetch a set of rows from data table
Posted
by cmrhema
on Stack Overflow
See other posts from Stack Overflow
or by cmrhema
Published on 2010-03-13T09:23:56Z
Indexed on
2010/03/13
9:35 UTC
Read the original article
Hit count: 337
Hi,
I have a dataset that has two datatables.
In the first datatable I have EmpNo,EmpName and EmpAddress
In the second datatable I have Empno,EmpJoindate, EmpSalary.
I want a result where I should show EmpName as the label and his/her details in the gridview
I populate a datalist with the first table, and have EmpNo as the datakeys.
Then I populate the gridview inside the datatable which has EmpNo,EmpJoinDate and EmpAddress.
My code is some what as below
Datalist1.DataSource = dt;
Datalist1.DataBind();
for (int i = 0; i < Datalist1.Items.Count; i++)
{
int EmpNo = Convert.ToInt32(Datalist1.DataKeys[i]);
GridView gv = (GridView)Datalist1.FindControl("gv");
gv.DataSource = dt2;
gv.DataBind();
}
Now I have a problem, I have to bind the Details of the corresponding Employee to the gridview. Whereas the above code will display all the details of all employees in the gridview.
If we use IEnumerable we give a condition where(a=>a.eno=EmpNo), and bind that list to the gridview.
How do I do this in datatable.
kindly do not give me suggestions of altering the stored procedure which results the values in two tables, because that cannot be altered. I have to find a solution within the existing objects I have.
Regards Hema
© Stack Overflow or respective owner