Results 1 to 2 of 2

Thread: programmatically access a control in ItemTemplate

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Bradenton, FL
    Posts
    87

    programmatically access a control in ItemTemplate

    How do I programmatically access a control inside the ItemTemplate of a DataList control? I want to set the .Visible property of a button depending on if the user is currently logged in or not.

    Here's the ItemTemplate element of my DataList control. It contains a label and a button (btnEdit). The btnEdit is what I want to set visible/invisible (in the Page_Load event):
    VB Code:
    1. <ItemTemplate>
    2.                 <asp:Label id="lblName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'>
    3.     </asp:Label><BR>
    4.  
    5.     <asp:Button id="btnEdit" Text="Edit" Runat="server" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "EmployeeID") %>' CommandName="Edit">
    6.     </asp:Button>
    7. </ItemTemplate>

    I just need the syntax to access the btnEdit control which is inside the ItemTemplate of a Datalist.

    Thanks,
    Greg

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    This code bit should show you what you need. Needs to be in the DataGrid's ItemDataBound event.

    John

    Code:
       // put alert on the delete button
       // From DotNetJunkies.com article
       // Steve Eichert
       // http://www.aspnextgen.com/howto/default.aspx?id=32
       if(e.Item.FindControl("btnDelete") != null)
           ((Button) e.Item.FindControl("btnDelete")).Attributes.Add("onClick", "return confirm('Are you sure you wish to delete this item?');");

Posting Permissions

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



Click Here to Expand Forum to Full Width