Gyorgy Bozoki
2007-10-16 04:39:01 UTC
Hi all,
I have a DataGrid on a web page (ASP.Net 2.0) and I need to go through each
DataGridItem when a button is pressed on the page. The grid has 5 columns
and one of the columns has an HtmlTable control with a single row and 10
columns and each column contains a CheckBox control.
When the button is clicked on the page, I go through the grid (100 rows, for
example) and I need to access each checkbox to see if it changed. Right now
this is what I do:
DataGridItem oItem;
DataGridItemCollection oItems;
CheckBox chkCheckBox;
...
for ( int i = 0, lCount = oItems.Count; i < lCount; i++ )
{
oItem = oItems[i];
chkCheckBox = oItem.FindControl ( "ControlName" );
if ( chkCheckBox != null )
{
...
}
}
I assume that each row in the DataGrid has the same order of these
checkboxes (since it's generated from the HTML designer template), so I was
wondering if it was possible to somehow cache the control indices for my 10
checkboxes, since I found that FindControl() is a very expensive call.
(Checked in Reflector.)
The problem is that all these controls are the children of the immediate
HTML table cell in which they're placed, not the DataGridItem, so using an
index instead of the name-based lookup seems out of question (all checkboxes
have a 0 index, because they're the only controls in each table cell.)
Is there anything I could do to do away with the unnecessary lookups and
recursive string matches of FindControl? I feel like I'm missing something.
Thanks,
Gyorgy Bozoki
===================================
This list is hosted by DevelopMentor� http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
I have a DataGrid on a web page (ASP.Net 2.0) and I need to go through each
DataGridItem when a button is pressed on the page. The grid has 5 columns
and one of the columns has an HtmlTable control with a single row and 10
columns and each column contains a CheckBox control.
When the button is clicked on the page, I go through the grid (100 rows, for
example) and I need to access each checkbox to see if it changed. Right now
this is what I do:
DataGridItem oItem;
DataGridItemCollection oItems;
CheckBox chkCheckBox;
...
for ( int i = 0, lCount = oItems.Count; i < lCount; i++ )
{
oItem = oItems[i];
chkCheckBox = oItem.FindControl ( "ControlName" );
if ( chkCheckBox != null )
{
...
}
}
I assume that each row in the DataGrid has the same order of these
checkboxes (since it's generated from the HTML designer template), so I was
wondering if it was possible to somehow cache the control indices for my 10
checkboxes, since I found that FindControl() is a very expensive call.
(Checked in Reflector.)
The problem is that all these controls are the children of the immediate
HTML table cell in which they're placed, not the DataGridItem, so using an
index instead of the name-based lookup seems out of question (all checkboxes
have a 0 index, because they're the only controls in each table cell.)
Is there anything I could do to do away with the unnecessary lookups and
recursive string matches of FindControl? I feel like I'm missing something.
Thanks,
Gyorgy Bozoki
===================================
This list is hosted by DevelopMentor� http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com