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

How can I add text to a label within a edititemtemplate field from another grid's itemcommand?

3 Answers 300 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 09 Mar 2015, 08:02 PM
I have two grids. The first is a graphic selecting grid:

    <telerik:radwindow runat="server" id="rwGraphics" visibleonpageload="false">
        <ContentTemplate>
            <asp:UpdatePanel ID="Updatepanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Literal ID="GraphicType" runat="server" Visible="false" />
                    <asp:Literal ID="CurrentID" runat="server" Visible="false" />                     
            <asp:Literal ID="litJS" Runat="server"/>
            <div align='center'>
            <table width='300' cellpadding='0' >
            <tr>
            <td width='100%' colspan="3" align='left'>

                                <telerik:RadGrid ID="rg_graphics" runat="server" AllowSorting="true" AutoGenerateColumns="false" Width="100%" GridLines="Both" 
                                    BorderStyle="None" ShowFooter="false" ShowHeader="true" AlternatingItemStyle-BackColor="WhiteSmoke" AllowAutomaticInserts="false" restrictionzoneId="ContentTemplateZone" >    
                                    <HeaderStyle BackColor="#000084" Font-Bold="true" ForeColor="White" HorizontalAlign='left' />
                                        
                                            <MasterTableView OverrideDataSourceControlSorting="true" DataKeyNames="GraphicId" ShowHeader="false"  >
                        <Columns>
                                                    <telerik:GridButtonColumn ItemStyle-Wrap="false"  CommandName="AddGraphic" ButtonType="LinkButton" Text="Add File" />
                        </Columns>
                <ItemTemplate >
                <asp:hyperlink runat='server' id='hl_graphic' Target='_blank' CssClass='login' navigateurl='<%#getGraphicPath(DataBinder.Eval(Container.DataItem, "GraphicID"))%>'><%#DataBinder.Eval(Container.DataItem, "Description")%></asp:hyperlink>
                </ItemTemplate>
                                        </MasterTableView>
                                    </telerik:RadGrid><br />
               <asp:Label ID='l_noresults' Runat='server'><font color='firebrick'><b>No Graphics Found</b></font></asp:Label>
            </td>
            </tr>
            </table>
            </div>

                </ContentTemplate>
            </asp:UpdatePanel>
        </ContentTemplate>
    </telerik:radwindow>    


The next grid is what calls the first grid.  


<tr>
                <td class="RightAlignHeader" width="1%" nowrap="nowrap">Answers</td>
                <td>
                    <telerik:RadGrid ID="rg_Answers" runat="server" AllowSorting="true" AutoGenerateColumns="false" Width="100%" GridLines="Both" 
                        BorderStyle="None" ShowFooter="false" ShowHeader="true" AlternatingItemStyle-BackColor="WhiteSmoke" AllowAutomaticInserts="false" >    
                        <HeaderStyle BackColor="#000084" Font-Bold="true" ForeColor="White" HorizontalAlign='left' />
                        <MasterTableView OverrideDataSourceControlSorting="true" CommandItemDisplay="Top" AllowSorting="true" DataKeyNames="AnswerId"  ShowHeadersWhenNoRecords="true" CommandItemSettings-AddNewRecordText="Add New Answer">
                            <Columns>
                                <telerik:GridButtonColumn UniqueName="btnDelete"  Text="Delete" ConfirmText="Confirm delete?" ButtonType="LinkButton" CommandName="Delete" ItemStyle-Width="1%" />
                                <telerik:GridButtonColumn UniqueName="btnEdit" Text="Edit" ButtonType="LinkButton" CommandName="Edit" ItemStyle-Width="1%" />                                    
                                <telerik:GridBoundColumn UniqueName="Text" DataField="Text" HeaderText="Answers" ItemStyle-Wrap="false" SortExpression="Text"/>                
                                <telerik:GridCheckBoxColumn UniqueName="IsCorrect" DataField="IsCorrect" HeaderText="Correct" SortExpression="IsCorrect" DefaultInsertValue="False" />                
                                <telerik:GridImageColumn UniqueName="AnswerGraphic" HeaderText="Graphic"/>
                                <telerik:GridTemplateColumn Display="false" UniqueName="AnswerGraphicColumn"  >
                                    <EditItemTemplate>
                                        <asp:Label ID="lbAnswerGraphicPath" runat="server" />
                                        <asp:LinkButton CommandName="UpdateAnswerGraphic"  cssclass='login' Runat='server' ID="lbAddGraphic">Update Answer Graphic</asp:LinkButton>
                                    </EditItemTemplate> 
                                </telerik:GridTemplateColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid><br />
                 </td> 
            </tr> 

Whenever a user selects something from the first grid it triggers an itemcommand in which I can get the graphic ID of the row.
I want to be able to then add text to the label of the second grid "lbAnswerGraphicPath" and close the window for this first grid.
My problem is that I cannot seem to access the rg_Answers label "lbAnswerGraphicPath" from within the rg_graphics.ItemCommand event.

I have tried this code:

For Each item As GridDataItem In rg_Answers.Items
Dim TestLabel As Label = DirectCast(item("AnswerGraphicColumn").FindControl("lbAnswerGraphicPath"), Label)
Next

However the TestLabel object always returns as nothing.  How can I access this label (and change the text within) from the rg_graphics.itemcommand event?

3 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 12 Mar 2015, 01:37 PM
Hi Patrick,

Try suing the approach below:
For Each item As GridDataItem In RadGrid1.Items
 
If TypeOf item  Is GridEditableItem AndAlso item.IsInEditMode Then
   Dim editableItem As GridEditableItem = TryCast(item, GridEditableItem)
   Dim TestLabel As Label = CType(editableItem.FindControl("lbAnswerGraphicPath"), Label)
    End If
     
Next


Regards,
Maria Ilieva
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Patrick
Top achievements
Rank 1
answered on 12 Mar 2015, 01:46 PM
There are no editableitems.  I should have been more specific that I am inserting (not editing) a new entry.   I want to update the label while in insert mode.   So far I cannot find a way to access that label while in insert mode outside of the grid events.
0
Patrick
Top achievements
Rank 1
answered on 13 Mar 2015, 01:22 PM
I finally was show a way from Telerik:

Dim LabelAnswerGraphic As Label =DirectCast(rg_Answers.MasterTableView.GetInsertItem().FindControl(lbAnswerGraphicPath), Label)LabelAnswerGraphic.Text = FHS.Settings.getGraphicPath(GraphicID)

This worked and assigns the text.   
Tags
Grid
Asked by
Patrick
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Patrick
Top achievements
Rank 1
Share this question
or