Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to bind a particular set of rows of datatable to DataGridView?

ProductExp talbe has
ProductExpNo
ProductNo
ExpDate

for example, i want to bind rows that has ProductNo=001

i also need other rows in that datatable but only want to show a set of rows to datagridveiw
Posted

Yes. Set a condition on your datatable, then bind it to your datagrid.

You could also use a stored procedure/query with a where clause to achieve the same result.
 
Share this answer
 
Comments
deva936 3-Jul-13 23:25pm    
Set a condition on your datatable? how?

i wrote "i also need other rows in that datatable"
so i can't use sql query

thanks
_Damian S_ 3-Jul-13 23:31pm    
http://msdn.microsoft.com/en-us/library/System.Data.DataTable.Select.aspx
deva936 4-Jul-13 4:42am    
when i bind the filtered rows to the DataGridView show nothing
so i test if it has actual retrieved rows
but i can retrieved like this
DataRow[] foundRows;

foundRows = dtPurchaseProductExp.Select(strFilterOption);

foreach (DataRow drfoundRows in foundRows)
{
MessageBox.Show(
drfoundRows["dtcolnPurchaseProductExpInvoiceNo"].ToString() + " : " +
drfoundRows["dtcolnPurchaseProductExpProductNo"].ToString());
}

what is worong? HELP
cant bind to datagridview
Hi,

Yes, you can do this by using select clause of data table.

Once you populate your data into data table, use select clause as below.

//This will populate your data into data table.
DataTable dtEmployees= GetData(splGetEmployees);

string strEmpID = 501;
string strTitle = "Manager";
string strFilterOption= "EmpId= " + strEmpID+ " AND Title = " + strTitle;

// bind the data with filtered rows using SELECT clause of datatable
datagrid.DataSourse = dtEmployees.Select(strFilterOption);
datagrid.Databind();



Enjoy coding....

Cheers
Kumar
 
Share this answer
 
v2
Comments
deva936 4-Jul-13 2:18am    
hello
thanks very much for yr reply

when i bind the filtered rows to the DataGridView show nothing
so i test if it has actual retrieved rows
but i can retrieved like this
DataRow[] foundRows;

foundRows = dtPurchaseProductExp.Select(strFilterOption);

foreach (DataRow drfoundRows in foundRows)
{
MessageBox.Show(
drfoundRows["dtcolnPurchaseProductExpInvoiceNo"].ToString() + " : " +
drfoundRows["dtcolnPurchaseProductExpProductNo"].ToString());
}

what is worong? HELP
cant bind to datagridview

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900