0

I have a radgrid in nested radgrid like below:

<telerik:RadGrid ID="RadGrid1" runat="server" GroupPanelPosition="Top" OnItemCommand="RadGrid1_ItemCommand">
    <GroupingSettings CollapseTooltip="Collapse all groups" />
    <MasterTableView AutoGenerateColumns="false" DataKeyNames="TicketID">
        <Columns>
            <telerik:GridBoundColumn DataField="Subject" FilterControlAltText="Filter Subject column" UniqueName="Subject">
            </telerik:GridBoundColumn>
        </Columns>
        <NestedViewTemplate>
            <telerik:RadGrid ID="RadGrid2" runat="server" GroupPanelPosition="Top" OnItemCommand="RadGrid2_ItemCommand">
                <GroupingSettings CollapseTooltip="Collapse all groups" />
                <MasterTableView AutoGenerateColumns="False">
                    <Columns>
                        <telerik:GridBoundColumn DataField="Body" FilterControlAltText="Filter Body column" UniqueName="Body">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn>
                            <ItemTemplate>
                                <asp:TextBox ID="txtAnswer" runat="server" Height="47px" TextMode="MultiLine"></asp:TextBox>
                                <asp:Button ID="btnAnswer" runat="server" CommandName="Answer" Text="Insert" />
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
        </NestedViewTemplate>
    </MasterTableView>
</telerik:RadGrid>

I want to access to textbox in inner RadGrid . I've used Item Command method like below:

protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e) 
{
    if (e.CommandName == "Answer") 
    {

        RadGrid Row = (RadGrid)((Button) sender).NamingContainer;
        TextBox txtAnswer = Row.FindControl("txtAnswer") as TextBox;
        string Body = txtAnswer.Text;
    }
}

but it's not working, full text of error: Unable to cast object of type 'Telerik.Web.UI.RadGrid' to type 'System.Web.UI.WebControls.Button'. What should I do?

Spawn
  • 935
  • 1
  • 13
  • 32
Mr Bitmap
  • 211
  • 4
  • 20
  • See this first http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-table-views-in-a-hierarchical-grid – rdmptn Dec 01 '15 at 13:05

1 Answers1

0

you can find nested grid view like this:

var NestedradGrid = 
    ((TargetRadGrid.MasterTableView.Items[0].ChildItem as GridNestedViewItem)
    .FindControl("NestedradGridID") as RadGrid);

Then you can find any control inside it. Read More: https://stackoverflow.com/a/25649846/709507

Community
  • 1
  • 1
Inside Man
  • 4,194
  • 12
  • 59
  • 119