Link to home
Create AccountLog in
Avatar of j-w-thomas
j-w-thomas

asked on

Cell Count in a DataGrid

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?
ASKER CERTIFIED SOLUTION
Avatar of prairiedog
prairiedog
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of j-w-thomas
j-w-thomas

ASKER

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
Are those textboxes dynamically created?
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.
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?
I assume the answer is no...

I appreciate your time though...

Thanks