Solved

Cell Count in a DataGrid

Posted on 2008-06-16
7
324 Views
Last Modified: 2008-06-16
Is there a way to get the count of cells in a datagrid?

To get the rows this works:

dgTest.Items.Count

But is there a way to count the number of cells in each row?
0
Comment
Question by:j-w-thomas
  • 4
  • 3
7 Comments
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 21797637
dgTest.Columns.Count
0
 
LVL 3

Author Comment

by:j-w-thomas
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...

Thanks,

John
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 21797778
Are those textboxes dynamically created?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Author Comment

by:j-w-thomas
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??
0
 
LVL 22

Expert Comment

by:prairiedog
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.
0
 
LVL 3

Author Comment

by:j-w-thomas
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...

Possible?

Worth while?
0
 
LVL 3

Author Comment

by:j-w-thomas
ID: 21798238
I assume the answer is no...

I appreciate your time though...

Thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Can't create users table in existing DB 16 60
call function 8 40
Async and await with MVC and Web Api 3 30
Jquery autocomplete 10 27
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now