Cell Count in a DataGrid

Is there a way to get the count of cells in a datagrid?

To get the rows this works:


But is there a way to count the number of cells in each row?
Who is Participating?
prairiedogConnect With a Mentor Commented:
j-w-thomasAuthor Commented:
That's great, but when I tested it, I realized that I needed one other thing.

I am using the "EDIT" function in a datagrid and I wanted to count the number of textboxxes that are in each row.

Sorry, I did not express that better first. I don't know if that is possible or not...


Are those textboxes dynamically created?
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

j-w-thomasAuthor Commented:
yes, using:

<asp:EditCommandColumn runat="server" CancelText="Cancel"
                                                    UpdateText="Update" EditText="Edit" />

When Edit is clicked the textboxes are created and trhe page is refreshed with the values of each cell are in each tectbox.

What I was hoping to do was to loop through each textbox before updating the info and validate the user's edits.

Does that make sense??
In this case, you already know the number of textboxes, because basically each editable cell will become a textbox for editing. As far as validation is concerned, it is better not to loop through all textboxes, but do is this way in your event handler that handles update:
dim txt1 as textbox = ctype(row.Cells(0).Controls(0), TextBox)
dim txt2 as textbox = ctype(row.cells(1).Controls(0), TextBox)
dim txt3 as textbox = ctype(row.cells(2).Controls(0), TextBox)
Then do the validation for each textbox. I assume the textboxes above are in column 1, 2,and 3 respecitvly.
j-w-thomasAuthor Commented:
Yes, my motive was to create a page that would programitcally adjust to an additional cell...

intCount = 0

dim txt1 as textbox = ctype(row.Cells(intCount).Controls(0), TextBox)

Then I could loop through it to create a variable for each one...the idea being if I add a column to the db I would not need to adjust the code.

I am probably dreaming in color, true??

I use the type of example you suggested already, I was hoping to add some steroids to it and make it self-adjusting...


Worth while?
j-w-thomasAuthor Commented:
I assume the answer is no...

I appreciate your time though...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.