Cell Count in a DataGrid

Posted on 2008-06-16
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 500 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

687 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