Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
List<orderdetail> objOrderDetail = new List<orderdetail>();
//Todo get all the grid order



foreach (GridViewRow gr in GridView.Rows)
{
objOrderDetail.Add(new OrderDetail
{
Code = int.Parse(((Label)(gr.FindControl("lblcode"))).Text),
Descritpion = ((Label)(gr.FindControl("lbldescription"))).Text,
Rate = int.Parse(((Label)(gr.FindControl("lblrate"))).Text),
Qty = int.Parse(((Label)(gr.FindControl("lblqty"))).Text),
Total = ((Label)(gr.FindControl("lbltotal"))).Text
});

}

obj.OrderDetails = objOrderDetail;
AdoData objado = new AdoData();
lblmessage.Text = objado.orderdetails(obj);
Posted
Updated 18-Dec-12 23:15pm
v4
Comments
Dhritirao's 19-Dec-12 5:46am    
here i m able to store only the last row in grid view how to store all rows in gridview.....

1 solution

The lists is a generics structure, you cannot declare a list on it's own. so instead of declaring the list variable as

C#
List objOrderDetail = new List();


in your first statement do it like this:

C#
List<orderdetail> objOrderDetail = new List<orderdetail>(); </orderdetail></orderdetail>


Please read about lists further at:

http://www.dotnetperls.com/list[^]

Regards
Pawan
 
Share this answer
 
Comments
Rai Pawan 18-Dec-12 5:21am    
Please try to debug the code and find out the line where the exception is raised. however there are two other lines where i think the problem may be. You are directly putting the label into description and total variables without proper type conversion.

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