|
|
|
start date: Tue, 03 Jul 2007 01:16:31 -0000,
posted on: microsoft.public.dotnet.framework.aspnet.buildingcontrols
back
| Thread Index |
|
1
unknown
|
|
2
Sergey Poberezovskiy
|
|
3
unknown
|
Get reference to control in gridview at runtime...
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?
Date:Tue, 03 Jul 2007 01:16:31 -0000
Author:
|
RE: Get reference to control in gridview at runtime...
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?
>
>
Date:Mon, 2 Jul 2007 19:32:04 -0700
Author:
|
Re: Get reference to control in gridview at runtime...
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.
Date:Tue, 03 Jul 2007 22:15:04 -0000
Author:
|
|
|