Hi,
Plesae let us know how to achieve the following.
1. Avoid loading the user control in nested view template when outer grid/page loads.
2. Allow loading of user control ONLY for the expanded row of the outer grid.
Find below the source code to work on. Any prompt help on this is really appreciated.
Note: The source code really doesn't have any parent and child relation in the data that it displays because it just a sample.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="NVT._Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register Src="PlayerDetails.ascx" TagName="PlayerDetails" TagPrefix="Player" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
telerik:RadScriptManager
ID
=
"scriptManager"
runat
=
"server"
></
telerik:RadScriptManager
>
<
telerik:RadGrid
ID
=
"grdPlayers"
runat
=
"server"
OnNeedDataSource
=
"GetPlayers"
AutoGenerateColumns
=
"true"
OnItemCommand
=
"grdPlayers_ItemCommand"
OnItemCreated
=
"grdPlayers_ItemCreated"
>
<
MasterTableView
>
<
NestedViewTemplate
>
<
asp:Panel
runat
=
"server"
ID
=
"InnerContainer"
Visible
=
"false"
>
<
Player:PlayerDetails
id
=
"ucPlayerDetails"
runat
=
"server"
></
Player:PlayerDetails
>
</
asp:Panel
>
</
NestedViewTemplate
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
div
>
</
form
>
</
body
>
</
html
>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
namespace NVT
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GetPlayers(object source, GridNeedDataSourceEventArgs e)
{
DataSet dsPlayers = new DataSet();
DataTable tblPlayers = new DataTable();
tblPlayers.Columns.Add("Name");
tblPlayers.Columns.Add("Age");
tblPlayers.Rows.Add("Sachin", "36");
tblPlayers.Rows.Add("Virender", "30");
dsPlayers.Tables.Add(tblPlayers);
grdPlayers.DataSource = dsPlayers;
}
protected void grdPlayers_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem)
{
((GridDataItem)e.Item).ChildItem.FindControl("InnerContainer").Visible =
!e.Item.Expanded;
}
}
protected void grdPlayers_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridNestedViewItem)
{
e.Item.FindControl("InnerContainer").Visible = ((GridNestedViewItem)e.Item).ParentItem.Expanded;
}
}
}
}
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PlayerDetails.ascx.cs" Inherits="NVT.PlayerDetails" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<
telerik:RadGrid
ID
=
"grdPlayerDetails"
runat
=
"server"
AutoGenerateColumns
=
"true"
>
</
telerik:RadGrid
>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
namespace NVT
{
public partial class PlayerDetails : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
GetPlayerDetails();
grdPlayerDetails.DataBind();
}
protected void GetPlayerDetails()
{
DataSet dsPlayerDetails = new DataSet();
DataTable tblPlayerDetails = new DataTable();
tblPlayerDetails.Columns.Add("Name");
tblPlayerDetails.Columns.Add("Age");
tblPlayerDetails.Rows.Add("Sachin", "36");
tblPlayerDetails.Rows.Add("Virender", "30");
dsPlayerDetails.Tables.Add(tblPlayerDetails);
grdPlayerDetails.DataSource = dsPlayerDetails;
}
}
}
Thanks,
Kishore