【发布时间】:2018-04-16 05:20:58
【问题描述】:
当我需要将 RadGrid 从首页移动到代码时遇到了这种情况。
以前是这样的:
<telerik:RadGrid id="rgBooks" runat="server"
Height="300px"
Skin="Office2007"
EnableViewState="true"
AutoGenerateColumns="False" >
<MasterTableView
EditMode="inplace"
TableLayout="auto"
ClientDataKeyNames="BookID, BookName, Created, Modified, BookTypeName, BookTypeID"
NoMasterRecordsText="No available books." >
<HeaderStyle Font-Bold="true" Font-Size="Small" />
<ItemStyle Font-Size="Small" Font-Names="Arial" HorizontalAlign="Left" Wrap="True" BackColor="White"/>
<HeaderStyle Wrap="False" Width="99%" HorizontalAlign="Left"/>
<AlternatingItemStyle Font-Size="Small" Font-Names="Arial" HorizontalAlign="Left" Wrap="True" BackColor="White"/>
<NestedViewTemplate>
<table>
<tr>
<td>
BookType Type:
</td>
<td>
<asp:DropDownList runat="server" ID="ddlBookTypes" AutoPostBack="true" />
</td>
</tr>
....
....
</NestedViewTemplate>
<columns>
<telerik:GridBoundColumn HeaderText="Book Name" HeaderStyle-Width="33%" ItemStyle-Width="33%" UniqueName="BookName" DataField="BookName" />
<telerik:GridBoundColumn HeaderText="Created" HeaderStyle-Width="33%" ItemStyle-Width="33%" UniqueName="Created" DataField="Created" />
<telerik:GridBoundColumn HeaderText="Modified" HeaderStyle-Width="33%" ItemStyle-Width="33%" UniqueName="Modified" DataField="Modified" />
</columns>
....
....
</telerik:RadGrid>
在代码中重新创建它看起来像这样:
Dim rgBooks As New RadGrid : With rgBooks
.ID = "rgBooks"
.Height = New Unit(300, UnitType.Pixel)
.Skin = "Office2007"
....
....
End With
Me.placeHolder.Controls.Add(rgBooks)
除了<NestedViewTemplate>,它工作正常。没有找到将我的值(表)发送到那里的方法,并且实际上没有关于如何执行此操作的文档。
据我了解,它应该看起来像rgBooks.MasterTableView.NestedViewTemplate.InstantiateIn( and here my data ),但每次尝试发送到那里都以失败告终,除了Object reference not set to an instance of an object.
还尝试作为 LiteralControl 发送。
rgBooks.MasterTableView.Controls.Add(New LiteralControl("<NestedViewTemplate>"))
rgBooks.MasterTableView.Controls.Add(New LiteralControl("<table>"))
rgBooks.MasterTableView.Controls.Add(New LiteralControl("<tr>"))
....
....
没有成功。
我想如何在代码中正确填写NestedViewTemplate(顺便说一下是ITemplate)?
【问题讨论】:
-
"填充" ?你的意思是
bind? -
对不起,我英文不好,但如果可以理解,我很高兴:) 不确定,也许 bind 是一个正确的词
-
感谢您的链接,但不幸的是,那里的示例非常糟糕。它绑定了来自代码查找的数据,但我需要从后面的代码创建一个完整的 NestedViewTemplate
-
还有更多的例子和资料,请搜索bind RadGrid NestedViewTemplate........祝你好运。
标签: vb.net telerik telerik-grid