This question was previously posted, solutions were given and then it was deleted, why I do not know.
But this is the solution I provided:
Your issue relates to when the new datarow is created. I would change your code to this:
protected DataTable tblGridRow()
{
int counta = Convert.ToInt32(Session["AddToListCount"]);
for (int i = 0; i < counta; i++)
{
DataRow dr = dt.NewRow();
dr["LG_ITEM_DSC"] = oDS.Tables[0].Rows[0]["LG_ITEM_DSC"].ToString();
dr["MFR_SKU_NUM"] = oDS.Tables[0].Rows[0]["MFR_SKU_NUM"].ToString();
string Price = oDS.Tables[0].Rows[0]["LIST_AMT"].ToString();
int length = Price.Length;
dr["LIST_AMT"] = Price.Remove(length - 2, 2);
dr["BRND_LOGO"] = oDS.Tables[0].Rows[0]["BRND_LOGO"].ToString();
dr["INV_UN_CDE"] = oDS.Tables[0].Rows[0]["INV_UN_CDE"].ToString();
dt.Rows.Add(dr);
}
return dt;
}
I would also consider changing your for loop because at the moment it will just input the same line X number of times (where X = counta).
I would suggest changing the for loop declaration to this:
int countLimit = counta <= oDS.Tables[0].Rows.Count ? counta : oDS.Tables[0].Rows.Count;
for (int i = 0; i < countLimit ; i++)
I would also replace all instances of
Rows[0]
with
Rows[i]
If that solves your issue please accept the answer.