how to find control in ItemTemplate of datagrid

Discussion in 'ASP .Net Datagrid Control' started by Daniel, Jun 29, 2004.

  1. Daniel

    Daniel Guest

    hi,
    I had a linkbutton control in ItemTemplate, but i don't know how to find
    it. Shall i use findcontrol?

    ~thanks.

    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
     
    Daniel, Jun 29, 2004
    #1
    1. Advertising

  2. Hi Daniel,

    As for how to retrieve a control in the DataGrid's ItemTemplate, you can
    just use the FindControl method. First, get the reference to the certain
    DataGridItem, then, use FindControl method on the proper Cell( which
    contains the control). For example, here is a code snippet on find a
    TextBox control in the datagrid's ItemDataBound event

    private void dgMain_ItemDataBound_1(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem)
    {
    TextBox txt = (TextBox)e.Item.Cells[2].FindControl("txtSub");
    Response.Write("<br>" + txt.ClientID +" | " + txt.UniqueID );
    }
    }

    And here are some other webreouces dicusssing on this :

    http://www.c-sharpcorner.com/Code/2003/Jan/AccessDataGridVal.asp

    http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=hijtbu8qli0rishmm
    q4tcg4ub6lla9nr2c%404ax.com&rnum=5&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF
    -8%26q%3Dasp.net%2Bdatagrid%2Bfind%2Bcontrol

    http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=fgsSSx39DHA.1988%
    40cpmsftngxa07.phx.gbl&rnum=16&prev=/groups%3Fq%3Dasp.net%2Bdatagrid%2Brefer
    ence%2Bcontrol%26hl%3Den%26lr%3D%26ie%3DUTF-8%26start%3D10%26sa%3DN

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
     
    Steven Cheng[MSFT], Jun 29, 2004
    #2
    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. Bennett Haselton
    Replies:
    1
    Views:
    5,412
    Joe Fallon
    Sep 24, 2004
  2. =?Utf-8?B?RGFiYmxlcg==?=
    Replies:
    2
    Views:
    3,538
    =?Utf-8?B?RGFiYmxlcg==?=
    Apr 12, 2006
  3. Borked Pseudo Mailed

    Cannot read ItemTemplate control values from Datagrid

    Borked Pseudo Mailed, Feb 7, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    390
    Borked Pseudo Mailed
    Feb 7, 2007
  4. AlecL
    Replies:
    3
    Views:
    1,284
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Apr 11, 2007
  5. Replies:
    0
    Views:
    166
Loading...

Share This Page