Get reference to control in gridview at runtime...

Discussion in 'ASP .Net Building Controls' started by huntco@gmail.com, Jul 3, 2007.

  1. Guest

    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?
     
    , Jul 3, 2007
    #1
    1. Advertising

  2. 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;
    }
    }

    "" 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?
    >
    >
     
    Sergey Poberezovskiy, Jul 3, 2007
    #2
    1. Advertising

  3. Guest

    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.
     
    , Jul 3, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DotNetJunkies User
    Replies:
    0
    Views:
    454
    DotNetJunkies User
    Jun 26, 2004
  2. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    18,008
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  3. Hal Vaughan
    Replies:
    11
    Views:
    1,154
    Gordon Beaton
    May 22, 2006
  4. Replies:
    5
    Views:
    678
  5. Sergio E.

    get data that fills gridview inside the gridview

    Sergio E., Aug 8, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    231
    Sergio E.
    Aug 8, 2007
Loading...

Share This Page