嗨,我在玩 radgrid 上的嵌套功能。如何在 OnItemDataBound 事件中引用和绑定嵌套在父 Radgrid 中的 rad 网格。
我试过了
var doc_grid = (RadGrid) item["doc_grid"].Controls[0];
var doc_grid = (RadGrid)RadGrid1.FindControl("doc_grid");
我是否必须参考 NestView ...
这是代码的一般要点...
<telerik:RadGrid ID="outerGrid" DataSourceID="SQL_Outer" runat="server" AutoGenerateColumns="True" OnItemDataBound="RowBound" DataKeyNames="MatNo"
ShowGroupPanel="True">
<MasterTableView DataSourceID="SQL_Outer" AllowMultiColumnSorting="True" DataKeyNames="MatNo" GroupLoadMode="Server">
<Columns>
<%--Stuff--%>
</Columns>
<NestedViewSettings DataSourceID="SqlDataSource2">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="sysid" MasterKeyField="MatNo" />
</ParentTableRelation>
</NestedViewSettings>
<NestedViewTemplate>
<asp:Panel ID="NestedViewPanel" runat="server" CssClass="viewWrap">
<div class="contactWrap">
<telerik:RadGrid ID="doc_grid" runat="server">
<MasterTableView AutoGenerateColumns="False" DataKeyNames="sysid">
<%--Stuff--%>
</MasterTableView>
</telerik:RadGrid>
</div>
</asp:Panel>
</NestedViewTemplate>
</MasterTableView>
</telerik:RadGrid>
代码隐藏:
protected void RowBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
var item = (GridDataItem)e.Item;
var mat_no = item.GetDataKeyValue("MatNo");
//!!!!I Can't figure out how to Reference the Inner RadGrid!!!!
//var doc_grid = (RadGrid) item["doc_grid"].Controls[0];
var doc_grid = (RadGrid)RadGrid1.FindControl("doc_grid");
using (var con = new SqlConnection())
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["TimeMatters11ConnectionString"].ConnectionString;
var cmd = new SqlCommand("SELECT sysid, ccode, [desc], [View] = '<a href=\"'+ filename + '\">View Doc</a>' " +
"FROM lntmu11.document " +
"WHERE mat_no = @matno", con);
cmd.Parameters.AddWithValue("@matno", mat_no);
con.Open();
var reader = cmd.ExecuteReader();
doc_grid.DataSource = reader;
doc_grid.DataBind();
con.Close();
}
}
提前致谢 ...