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
605
Controls in template column dissapear after adding rows
posted

Hello, I have an ultrawebgrid.  The first column is a template column with an imagebutton as the only control.  once I click the add new button, the row appears, but the control is not there.  Any help would be appreciated.  Below is the templated column in the webgrid.

 

<igtbl:TemplatedColumn AllowGroupBy="No" FilterIcon="False" ServerOnly="false"  >
                                <CellTemplate>
                                    <asp:ImageButton ID="btnDeleteResource"  runat="server" ImageUrl="~/images/delete.png" CommandArgument="Delete" OnClientClick="return confirm('Delete Selected Row?');" CommandName="Delete" />
                                    <asp:Button runat="server" Text="test" />
                                </CellTemplate>
                               
                                <Header>
                                <RowLayoutColumnInfo OriginX="1"></RowLayoutColumnInfo>
                                </Header>

                                <Footer>
                                <RowLayoutColumnInfo OriginX="1"></RowLayoutColumnInfo>
                                </Footer>
                            </igtbl:TemplatedColumn>

Parents
  • 45049
    Verified Answer
    posted

    Controls in a templated column must be instantiated on the server before they can be displayed on the client.  This typically requires you to perform a postback on the page before the controls for the new cell in the templated column will appear.

    If it's possible for you to do so, it's better to use the built-in functionality of the grid, instead of column templates.  It is typically less work to implement.  More importantly, it provides better performance, since instantiating ASP.NET templates is a computationally-expensive process.  Of course, templated columns are more flexible, so there are some approaches for which you'll have to use a tempalted column (or consider an alternate approach).

    For a situation like this, where you have a button that is meant to perform an action on the grid row, I recommend to use a WebGrid column with a Type of Button, instead of a templated column containing an image button.  You can use the server-side and client-side CellClickButton events of the grid to process what to do when such a button is clicked, both which give you references to the cell that contains the button that was clicked.

    I notice that you have two buttons in your column template.  For the Button-type column, you can have exactly one button in the column.  If displaying multiple buttons is important, you may want to have one column for each button.  If you absolutely need to have them all in the same cell, then a templated column is your only viable option.

Reply Children