Reputation: 61
I am trying to use looping to get some data and bind into existing Gridview
for (int i =0; i<datasetResult.Rows.Count; i++){
//some code to retrieve data from DB
//after retrieved i am trying to bound it into my datagrid but i failed
DataRow dr = datasetResult.Tables[0].Rows[i];
if(RetVal ==0){
dataGridView.DataSource = datasetResult.Table[0];
}
}
My result failed to append, the end result is the last data row of my retrieved data this is because every-time when there are new input it will only bind for once but never append, the second result will replaced the first result.
Upvotes: 0
Views: 133
Reputation: 7092
You're trying to retrieve the data inside the for loop
and that's not the proper way.
Assuming you have data already in your DataTable
and This one line of code will work for you.
dataGridView.DataSource = datasetResult.Table[0];
Upvotes: 2