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

Access to edit form template objects from code behind

3 Answers 417 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 15 Apr 2009, 03:50 PM

While I'm at it . . .

I have an edit form template which is nested in a panel bar.  I'm having trouble accessing the form objects in the template from the code behind.  Here is the panel bar/grid/template:

 

<telerik:RadPanelBar runat="server" ID="panelDisputeHistory" Skin="Web20" Width="98%">  
                <CollapseAnimation Type="None"></CollapseAnimation> 
                    <Items> 
                        <telerik:RadPanelItem Text="Dispute History" Expanded="False">  
                            <Items> 
<telerik:RadPanelItem Text="" Value="pnlItemDisputeHistory">  
                                    <ItemTemplate> 
                                        <div> 
                                            <!-- Begin dispute history section -->         
                                            <telerik:RadGrid ID="grdDisputes" runat="server" DataSourceID="sqlDisputes" Skin="Default" 
                                            AllowPaging="false" AllowSorting="True" 
                                            FilterItemStyle-HorizontalAlign="center" Width="700px" Height="400px"   
                                            ShowStatusBar="false" GridLines="Both" 
                                            AutoGenerateColumns="False" HeaderStyle-Font-Size="X-Small" HorizontalAlign="NotSet"   
                                            OnUpdateCommand="grdDisputes_UpdateCommand" CommandItemDisplay="Top"   
                                            OnInsertCommand="grdDisputes_InsertCommand" OnDeleteCommand="grdDisputes_DeleteCommand" OnItemDataBound="grdDisputes_ItemDataBound">    
<MasterTableView DataSourceID="sqlDisputes" PageSize="50" 
                                                    Width="700px" DataKeyNames="ID" ItemStyle-Font-Size="X-Small">    
                                                    <Columns> 
</Columns> 
<EditFormSettings EditFormType="Template">  
                                                         <EditColumn uniquename="EditCommandColumn1"></EditColumn> 
                                                         <FormTemplate> 
                                                              
                                                            <table width="100%" cellpadding="2" cellspacing="2" border="0" class="standard_table_no_border">  
                                                                <tbody>                                                              
                                                                    <tr> 
                                                                        <td style="" colspan="3">Invoice Amount  
                                                                            <asp:TextBox ID="txtInvoiceAmt" runat="server" width="50" Font-Size="X-Small"  Text='<%#Eval("INVOICE_AMT", "{0:n2}") %>'></asp:TextBox>&nbsp;  
</td> 
                                                                    </tr>   
 </tbody> 
                                                            </table> 
</FormTemplate> 
                                                         <PopUpSettings ScrollBars="None" /> 
                                                    </EditFormSettings>   
                                                      
                                                </MasterTableView> 
                                            </telerik:RadGrid> 
                                            <!-- End dispute section -->                                      
                                        </div> 
                                    </ItemTemplate> 
                                </telerik:RadPanelItem> 
                            </Items> 
                        </telerik:RadPanelItem>                  
                    </Items> 
                <ExpandAnimation Type="None"></ExpandAnimation> 
            </telerik:RadPanelBar>             

I've tried a dozen different ways of accessing txtInvoiceAmt, none with success.  The basis of my attempts is some form of:

TextBox txtInvoiceAmt = (TextBox)panelDisputeHistory.FindItemByValue("pnlItemDisputeHistory").FindControl("grdDisputes").FindControl("txtInvoiceAmt");  
 

 

Nothing seems to work.  Any ideas?

 

Thanks again.

 

Rich

3 Answers, 1 is accepted

Sort by
0
Russ
Top achievements
Rank 1
answered on 15 Apr 2009, 04:37 PM
I struggeld with something similar, recently.  You might be better off going throuhg the various levels a step at a time.  Also, adding an id to the second item level might help a little, but you should be able to get through that piece with something like this (untested):

 

 

 

 

RadPanelItem mainPanel = ((RadPanelItem)(panelDisputeHistory.Items[0].Items[0]));   
   
// then find the grid within that panel item:  
 
RadGrid panelGrid = (RadGrid)mainPanel.FindControl("grdDisputes");   
 

 

 

 

 

Then use normal grid methods on the "panelGrid" to get the controls within it (I haven't done much with accessing a template form, but I think there are some good examples in this site).

Good Luck. 
Russell.

 

0
Rich
Top achievements
Rank 1
answered on 15 Apr 2009, 07:03 PM
Using your approach (thank you, by the way) I can almost get there but not quite.  I can get from the main panel to the panel item to the grid which contains the edit form template, but no further.  I can't figure out how to access the form objects directly off the grid.  I thought maybe I needed a reference to "EditCommandColumn1" first but that didn't work.

Here's what I've tried:

RadPanelBar mainPanel = (RadPanelBar)this.panelDisputeHistory;  
RadPanelItem panelItem = (RadPanelItem)mainPanel.FindItemByValue("pnlItemDisputeHistory");  
RadGrid grd = (RadGrid)panelItem.FindControl("grdDisputes");  
//the following line of code does not compile  
EditCommandColumn eCol = (EditCommandColumn)grd.FindItemByValue("EditCommandColumn1");  
//TextBox txt = (TextBox)grd.FindControl("txtInvoiceAmt");  
 
Response.Write(mainPanel.UniqueID + "<br>");  
Response.Write(panelItem.UniqueID + "<br>");  
Response.Write(grd.UniqueID + "<br>");  
//the following line of code produces an error  
//Response.Write(txt.UniqueID + "<br>"); 


Any other ideas?
0
PV
Top achievements
Rank 1
answered on 03 Jun 2010, 08:13 AM
Hope you are looking for this:

protected

 

void grdDisputes_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

 

GridEditableItem editedItem = e.Item as GridEditableItem;

 


 

string invoiceamt= (editedItem.FindControl("txtInvoiceAmt") as TextBox).Text;

etc...

-Prema

 

Tags
Grid
Asked by
Rich
Top achievements
Rank 1
Answers by
Russ
Top achievements
Rank 1
Rich
Top achievements
Rank 1
PV
Top achievements
Rank 1
Share this question
or