[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

Get reference to control in gridview at runtime...

huntco@gmail.com

7/3/2007 1:17:00 AM

I have a gridview control with a headertemplate (and other
templates). In that headertemplate, I have some controls (a textbox,
for example, used to filter the data in the gridview). When the user
clicks a button on the page (the "filter" button), I need to grab the
value (text) of that control - but I'm having a difficult time getting
a reference to it.

FindControl("controlName") doesn't do it. I've tried iterating
through all the controls (recursively) looking for one with the
"controlName" as the ID, but I've hit recursion "infinite loop"
warnings. Scoping for particular object types (to cut down on the
recursive loops) doesn't work either.

How do I reference an object at runtime that's buried several layers
within another object?

2 Answers

Sergey Poberezovskiy

7/3/2007 2:32:00 AM

0

inside GridView_RowCreated event:
if (e.RowType == DataControlRowType.Header){
// here you will need to reference the cell containing your textbox
TableCell cell = e.Cells[myTextBoxCellIndex];
foreach (Control control in cell.Controls){
if (control is TextBox)
string myText = control.Text;
}
}

"huntco@gmail.com" wrote:

> I have a gridview control with a headertemplate (and other
> templates). In that headertemplate, I have some controls (a textbox,
> for example, used to filter the data in the gridview). When the user
> clicks a button on the page (the "filter" button), I need to grab the
> value (text) of that control - but I'm having a difficult time getting
> a reference to it.
>
> FindControl("controlName") doesn't do it. I've tried iterating
> through all the controls (recursively) looking for one with the
> "controlName" as the ID, but I've hit recursion "infinite loop"
> warnings. Scoping for particular object types (to cut down on the
> recursive loops) doesn't work either.
>
> How do I reference an object at runtime that's buried several layers
> within another object?
>
>

huntco@gmail.com

7/3/2007 10:15:00 PM

0

Thanks. Tweaked it a little bit, but that was the nudge in the right
direction that I needed.

I wound up creating private objects (textbox) in the class that
parallel the objects I'm looking for in the gridview. Then "on page
load," I cycle through gridview.headerrow like you have outlined
(page_load vice rowCreated) and link each of the textbox controls to
their corresponding private textboxes at the class level. That way I
always have a reference to the "deeper" objects at the class level.

Thanks again.