Click here to Skip to main content
14,301,147 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi Guys,
How do i loop through a data grid with say two columns where Column A is a pulldown of products and Column B is a Text box. let say the data grid has ten rows, with four of the rows have pulldown with Product ID=A1, three with Product ID=A2,two with Product ID=A3 and one with Product ID=A4. I would like to be able to loop through summing the the text box values for each group of Product ID.
Posted
Comments
GenJerDan 6-Dec-10 15:46pm
   
Are you absolutely sure you wouldn't rather do this on the underlying datasource?
wizardzz 6-Dec-10 17:26pm
   
I second what GenJerDan said. It seems like you are going the long way about this problem.
Rate this:
Please Sign up or sign in to vote.

Solution 1

You need to use the RowBound event of the data grid.
Using FindControl method get reference of the text box inside data grid and store its value in a viewstate variable(summing it).

example:
ViewState["sum"] = Convert.ToInt32(ViewState["sum"]) + number;

Display the viewstate variable wherever you want and it will show the total sum.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

This[^] thread might help. It discusses a number of approaches.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100