Cell Count in a DataGrid

Posted on 2008-06-16
Medium Priority
Last Modified: 2008-06-16
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?
Question by:j-w-thomas
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 22

Accepted Solution

prairiedog earned 2000 total points
ID: 21797637

Author Comment

ID: 21797727
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...


LVL 22

Expert Comment

ID: 21797778
Are those textboxes dynamically created?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 21797826
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??
LVL 22

Expert Comment

ID: 21797945
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.

Author Comment

ID: 21797984
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?

Author Comment

ID: 21798238
I assume the answer is no...

I appreciate your time though...


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question