As seen from the following code given in the question,
for (int i = 0; i < dt.Rows.Count; i++)
{
lblmessage.Text = dt.Rows[i]["pair"].ToString();
}
each time the
gridtree_RowDataBound
event is fired, all rows of the
DataTable dt
are traversed in the for loop and the
lblmessage.Text
is set, which is being over written in each iteration. So the last value in the last row of the DataTable dt, which is
1
as seen from the data given in the question, will be visible in the lblmessage after the above event.
But I think, for the purpose of displaying the data in
GridView
a
DataTable
with columns
Id, pair
can be created and populated as per requirement. Then it can be used to bind to the gridview in a normal way. You can consider this alternative.