Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
80
Accessing Controls within TemplatedColumn
posted

Can someone give me some direction on how to get a handle to control, say an asp.net label, inside a templated column on a webgrid that was constructed at design time?

Parents
No Data
Reply
  • 28464
    posted

    In a templated column you can have any content - for example you can start with just a placeholder and then add controls there programmatically in the InitializeRow event. For example:

    <igtbl:TemplatedColumn>
        <CellTemplate>
            <asp:placeholder runat="server" ID="Placeholder1'>                        
        </CellTemplate>
    </igtbl:TemplatedColumn>

    and  then in InitializeRow, you can do something similar to this (pseudo code, just for reference)

    TemplatedColumn col = (TemplatedColumn)e.Row.Cells.FromKey("SomeKey").Column;
    CellItem ci = (CellItem)col.CellItems[e.Row.Index];
    Placeholder placeholder = (Placeholder) ci.FindControl("placeHolder1"); 

    if (e.Row.Index == 1)
        placeholder.Controls.Add(new Label("Some Text 1"));
    else
        placeholder.Controls.Add(new TextBox("Some Text 2"));
Children