This is a migrated thread and some comments may be shown as answers.

Command Button in Grid ItemTemplate?

3 Answers 183 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 20 Sep 2009, 04:01 PM
    Hi.  I'm in the process of converting a RadGrid using "traditional" columns to CardView, using ItemTemplate.  In the original grid, I had a GridButtonColumn to handle deleting, with a confirmation pop-up.  I want to keep this same behavior in the template.  Is there a way I can embed the original button column's behavior in the new template?

Thanks,
    Andrew

Here's my old grid:
                <telerik:RadGrid ID="ContentsRadGrid" runat="server" 
                    GridLines="None" 
                    OnNeedDataSource="ContentsRadGrid_NeedDataSource"   
                    ondeletecommand="ContentsRadGrid_DeleteCommand">  
                    <MasterTableView AutoGenerateColumns="false">  
                        <RowIndicatorColumn> 
                            <HeaderStyle Width="20px"></HeaderStyle> 
                        </RowIndicatorColumn> 
                        <ExpandCollapseColumn> 
                            <HeaderStyle Width="20px"></HeaderStyle> 
                        </ExpandCollapseColumn> 
                        <Columns> 
                            <telerik:GridBoundColumn HeaderText="Quantity" DataField="Quantity" /> 
                            <telerik:GridBoundColumn HeaderText="NDC" DataField="TheDrug.Ndc" /> 
                            <telerik:GridBoundColumn HeaderText="Name" DataField="TheDrug.DrugName" /> 
                            <telerik:GridBoundColumn HeaderText="Size" DataField="TheDrug.DrugSize" /> 
                            <telerik:GridBoundColumn HeaderText="Strength" DataField="TheDrug.DrugStrength" /> 
                            <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" 
                                ConfirmText="Delete medication from kit list?" /> 
                        </Columns> 
                    </MasterTableView> 
                </telerik:RadGrid> 
 

And here's the new one, so far:
                <telerik:RadGrid ID="RadGrid1" runat="server" 
                    GridLines="None" 
                    OnNeedDataSource="RadGrid1_NeedDataSource"   
                    ondeletecommand="ContentsRadGrid_DeleteCommand">  
                    <MasterTableView AutoGenerateColumns="false">  
                        <Columns> 
                            <telerik:GridBoundColumn HeaderText="Quantity" DataField="Quantity" Visible="false" /> 
                        </Columns> 
                        <ItemTemplate> 
                            <table style="width:100%;">  
                                <tr> 
                                    <td rowspan="2" style="text-align:center; width:15%">  
                                        Qty:<br /> 
                                        <%# Eval("Quantity") %> 
                                    </td> 
                                    <td colspan="2" style="white-space:nowrap;">  
                                        <%# Eval("TheDrug.Ndc.NdcString") %>&nbsp;  
                                        <span style="font-weight:bold;"><%# Eval("TheDrug.DrugName") %></span>  
                                    </td> 
                                    <td rowspan="2" style="text-align:center; width:10%">  
                                        DELETE LINK GOES HERE  
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td style="white-space:nowrap;">  
                                        Strength:&nbsp;  
                                        <%# Eval("TheDrug.DrugStrength") %> 
                                    </td> 
                                    <td style="white-space:nowrap;">  
                                        Size:&nbsp;  
                                        <%# Eval("TheDrug.DrugSize") %> 
                                    </td> 
                                </tr> 
                            </table> 
                        </ItemTemplate> 
                    </MasterTableView> 
                </telerik:RadGrid> 
 


3 Answers, 1 is accepted

Sort by
0
lakmal
Top achievements
Rank 2
answered on 20 Sep 2009, 06:01 PM
Yes you can do it

<ItemTemplate> 
                            <table style="width:100%;">  
                                <tr> 
                                    <td rowspan="2" style="text-align:center; width:15%">  
                                        Qty:<br /> 
                                        <%# Eval("Quantity") %> 
                                    </td> 
                                    <td colspan="2" style="white-space:nowrap;">  
                                        <%# Eval("TheDrug.Ndc.NdcString") %>&nbsp;  
                                        <span style="font-weight:bold;"><%# Eval("TheDrug.DrugName") %></span>  
                                    </td> 
                                    <td rowspan="2" style="text-align:center; width:10%">  
                                        DELETE LINK GOES HERE  
                                    </td> 
                                </tr> 
                                <tr> 
                                    <td style="white-space:nowrap;">  
                                        Strength:&nbsp;  
                                        <%# Eval("TheDrug.DrugStrength") %> 
                                    </td> 
                                    <td style="white-space:nowrap;">  
                                        Size:&nbsp;  
                                        <%# Eval("TheDrug.DrugSize") %> 
                                    </td> 
                                </tr> 
                            </table> 
                        </ItemTemplate>

  <Columns>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"                                  ConfirmText="Delete medication from kit list?" />







     </Columns>






0
Andrew
Top achievements
Rank 1
answered on 21 Sep 2009, 04:27 AM
Thanks for the quick response.  This is a good start -- the column appears and works.  Is there a way I can get it to appear at the end of the row, as indicated in my markup?  (As written it appears before the template in each row.)

Thanks,
  Andrew
0
Andrew
Top achievements
Rank 1
answered on 21 Sep 2009, 05:09 AM
    Never mind, I figured it out.  I needed to embed my ItemTemplate within the GridTemplateColumn.

Thanks,
    Andrew
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
lakmal
Top achievements
Rank 2
Andrew
Top achievements
Rank 1
Share this question
or