访问嵌套父级radgrid的内部radgrid中的TextBox
本文关键字:radgrid 内部 中的 TextBox 访问 嵌套 | 更新日期: 2023-09-27 18:24:58
我在嵌套的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"类型。我该怎么办?
您可以找到这样的嵌套网格视图:
var NestedradGrid =
((TargetRadGrid.MasterTableView.Items[0].ChildItem as GridNestedViewItem)
.FindControl("NestedradGridID") as RadGrid);
然后你可以在里面找到任何控制。阅读更多:https://stackoverflow.com/a/25649846/709507