Pierre Lebon Pierre Lebon -4 years ago 133
ASP.NET (C#) Question

Nested grid do not fire event

Here is a nested grid with some event :

<%--BLOCK : TEST--%>
<telerik:GridTableView CssClass="noColapse" runat="server" Name="RptPV" DataSourceID="LDS_PV_info" DataKeyNames="MSE_compteur" HierarchyDefaultExpanded="True"
OnCallingDataMethods="Unnamed_CallingDataMethods"
OnDataBinding="Unnamed_DataBinding"
OnDisposed="Unnamed_Disposed"
OnCreatingModelDataSource="Unnamed_CreatingModelDataSource"
OnDataBound="Unnamed_DataBound"
OnInit="Unnamed_Init"
OnLoad="Unnamed_Load"
OnPreRender="Unnamed_PreRender"
OnSelectedIndexChanged="Unnamed_SelectedIndexChanged"
OnUnload="Unnamed_Unload" >


Code behind:

protected void Unnamed_CallingDataMethods(object sender, CallingDataMethodsEventArgs e)
{ this.here.Text += "CallingDataMethods";}

protected void Unnamed_DataBinding(object sender, EventArgs e)
{ this.here.Text += "Unnamed_DataBinding";}

protected void Unnamed_Disposed(object sender, EventArgs e)
{ this.here.Text += "Unnamed_Disposed";}

protected void Unnamed_CreatingModelDataSource(object sender, CreatingModelDataSourceEventArgs e)
{ this.here.Text += "Unnamed_CreatingModelDataSource";}

protected void Unnamed_DataBound(object sender, EventArgs e)
{ this.here.Text += "Unnamed_DataBound";}

(...)


And my here.text stay empty. But the nested grid is displayed.

I need to access a parent key value, collapse a nested grid, hide a nested grid or count the number of row.

There will be no edit, no row click, those grid are only displaying data in templated columns > Item Template .

Is there a way for a nested grid to fire event?
In witch on those even may I access databounded information.

Answer Source

A nested grid DO NOT Fire event!

If you need to access detail tables , items etc .
You need to add an method to the PreRender in the MasterTableView like this:

<MasterTableView   DataSourceID="myDataSource"
                   AllowMultiColumnSorting="True" 
                   DataKeyNames="Key1,Key2,KeyN" 
                   HierarchyDefaultExpanded="True"
                   OnPreRender="Unnamed_PreRender" >

The method will iterate through the grid using recursively.
The way you do it can change depending on your HieararchyLoadMode.

So this is my way to do it, easiest way exist if you are on Client or Serverbind mode.

protected void Unnamed_PreRender(object sender, EventArgs e)
{
    // MyControler is my recursive method.
    MyControler(RadGRID_MASTER.MasterTableView);
}



private void MyControler(GridTableView gridTableView)
{
    GridItem[] nestedViewItems = gridTableView.GetItems(GridItemType.NestedView);    
    foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
    {
        foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
        {
            // Here you can operate your controls the way you want.
            if (nestedView.Name == "LAC" && nestedView.Items.Count == 0)
            {  
                // Do stuff 
            }

            if(nestedView.HasDetailTables)
            {
                MyControler(nestedView); 
            }
        }
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download