我在嵌套的radgrid中有一个radgrid,如下所示:
<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>
我想访问内部RadGrid中的文本框。我使用了Item Command方法 如下所示:
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;
}
}
但它不起作用,错误全文: 无法将“Telerik.Web.UI.RadGrid”类型的对象强制转换为“System.Web.UI.WebControls.Button”。 我该怎么办?
答案 0 :(得分:1)
你可以找到这样的嵌套网格视图:
var NestedradGrid =
((TargetRadGrid.MasterTableView.Items[0].ChildItem as GridNestedViewItem)
.FindControl("NestedradGridID") as RadGrid);
然后你可以在里面找到任何控件。 阅读更多:https://stackoverflow.com/a/25649846/709507