Re: How to quickly find control in DataGrid...

brian zinn <[email protected]> Wed, 17 Oct 2007 19:18:31 +0200
Newsgroups gmane.comp.windows.devel.dotnet.web
Message-ID <[email protected]>
Gyorgy,

Since you haven't gotten a reply yet, maybe check-out MetaBuilders
SelectorField[1] control - it's open source.  There are no FindControl
calls in the class itself, but I didn't bother checking it's base
class DataControlField or anything else, but maybe it's helpful.

Cheers,
Brian

On 10/16/07, Gyorgy Bozoki <[email protected]> wrote:
> 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(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com