how to find control in ItemTemplate of datagrid

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default how to find control in ItemTemplate of datagrid

    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: [url]http://www.opera.com/m2/[/url]
    Daniel Guest

  2. Similar Questions and Discussions

    1. Find Control in Datagrid
      Hi, I have a datagrid and I'm wanting to access one of the hyperlinks which is located in Template Column i.e. <asp:TemplateColumn...
    2. Datagrid with textboxes on itemtemplate
      Hello I have datagrid that by defect in a column of itemtemplate I place textbox. The application is of the goals of a soccer game Then it appears...
    3. datagrid itemtemplate help
      Dear All, In my datagrid, i want to add a logic to it. that is, if the result for the data equals to "Yes", a "asp:label" control will be...
    4. ItemCommand not firing w/ a control in ItemTemplate column
      I 've been dealing with this problem for a while now. I have a datagrid in which one column is a template column, encompassing textboxes (1 hidden,...
    5. DataGrid OnItemBound find control
      Fixed it, the first item received in the onItemBound event is the datagrid header, this doesn't contain the button. I just have to ensure that I...
  3. #2

    Default RE: how to find control in ItemTemplate of datagrid

    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 :

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

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

    [url]http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=fgsSSx39DHA.1988%[/url]
    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! [url]www.microsoft.com/security[/url]
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    [url]http://msdn.microsoft.com/asp.net/whidbey/default.aspx[/url]






    Steven Cheng[MSFT] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139