I need to get all the rows in a DataGridView in a foreach function. How can I do this?
I.E. foreach() for each row, so for each row I could run code that would utilize the first and second column data.
This is in c#
Thanks,
Christian
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think the best way of accessing this data is either through the
Data Source:OR, if the user is entering data on the page, you can access from the
FindControlmethod:In this case, if you’ve raised an event for a specific row, it will return
EventArgs e, with a specificRowIndex. Then you can access the Column values via theControlIDwithin the column, such as<asp:TextBox id="name" runat="server" />from.FindControl("name").The important thing to remember is that you have to cast that object back to the type that it should be from the
.FindControl()method.