Professional Web Applications Themes

how to find control in ItemTemplate of datagrid - ASP.NET Data Grid Control

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] continued...

  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. #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

Similar Threads

  1. Itemtemplate requires unique control's id's
    By Edwin Knoppert in forum ASP.NET Building Controls
    Replies: 0
    Last Post: December 11th, 11:29 AM
  2. Find Control in Datagrid
    By Jack in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: April 11th, 12:44 PM
  3. Datagrid with textboxes on itemtemplate
    By Luis Esteban Valencia in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: January 26th, 02:45 PM
  4. datagrid itemtemplate help
    By angus in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: June 20th, 08:28 PM
  5. DataGrid OnItemBound find control
    By trinitypete in forum ASP.NET General
    Replies: 0
    Last Post: August 1st, 10:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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