This is a migrated thread and some comments may be shown as answers.

Master/Detail declarative binding: detailsview empty

8 Answers 26 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Emanuele
Top achievements
Rank 1
Veteran
Emanuele asked on 11 Jan 2018, 02:50 PM

Hi, i'm trying to use RadGrid for a master/detail grid with declarative binding, but when i try to expand a level i obtain only empty detailsviews.

I set ServerOnDemand mode. This is the code.

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ElencoGruppi.aspx.cs" Inherits="Stats.Secure.ElencoGruppi" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
   
    <div class="row" id="er_head">
        <div class="col-md-12">
            <h2>Gestione gruppi</h2>
        </div>
    </div>
 
    <telerik:RadGrid ID="rgGruppi" runat="server" DataSourceID="sdsGruppi" AllowSorting="True" AlternatingItemStyle-BackColor="#fff7e9" AutoGenerateColumns="False" RenderMode="Lightweight" Skin="Silk" Culture="it-IT">
        <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
 
        <ExportSettings>
            <Pdf PageWidth="">
            </Pdf>
        </ExportSettings>
 
        <AlternatingItemStyle BackColor="#FFF7E9"></AlternatingItemStyle>
 
        <MasterTableView EnableHierarchyExpandAll="true" DataSourceID="sdsGruppi" DataKeyNames="IDGruppo" HierarchyLoadMode="Client" NoDetailRecordsText="Nessun dato di dettaglio trovato" NoMasterRecordsText="Nessun dato trovato">
            <DetailTables>
                <telerik:GridTableView EnableHierarchyExpandAll="true" DataKeyNames="IDReport" DataSourceID="sdsReport" Width="100%" runat="server">
                    <ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="IDGruppo" MasterKeyField="IDGruppo"></telerik:GridRelationFields>
                    </ParentTableRelation>
                    <Columns>
                        <telerik:GridBoundColumn DataField="IDReport" HeaderText="ID" UniqueName="IDReport" DataType="System.Int32">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Titolo" HeaderText="Titolo" UniqueName="Titolo">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="IDTipoReport" HeaderText="Tipo" UniqueName="IDTipoReport">
                        </telerik:GridBoundColumn>
                    </Columns>
                </telerik:GridTableView>
            </DetailTables>
            <Columns>
                <telerik:GridBoundColumn DataField="IDGruppo" HeaderText="ID" UniqueName="IDGruppo" DataType="System.Int32">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Gruppo" HeaderText="Gruppo" UniqueName="Gruppo">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Descrizione" HeaderText="Descrizione" UniqueName="Descrizione">
                </telerik:GridBoundColumn>
                <telerik:GridCheckBoxColumn DataField="Pubblicato" HeaderText="Pubblicato" UniqueName="Pubblicato" DataType="System.Boolean">
                </telerik:GridCheckBoxColumn>
                <telerik:GridBoundColumn DataField="Ordine" HeaderText="Ordine" UniqueName="Ordine" DataType="System.Int32">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="NumeroClick" HeaderText="Click" UniqueName="NumeroClick" DataType="System.Int32">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Url" HeaderText="Url" UniqueName="Url">
                </telerik:GridBoundColumn>
            </Columns>
        </MasterTableView>
 
        <FilterMenu RenderMode="Lightweight"></FilterMenu>
 
        <HeaderContextMenu RenderMode="Lightweight"></HeaderContextMenu>
    </telerik:RadGrid>
 
    <asp:SqlDataSource ID="sdsGruppi" runat="server" ConnectionString=""
        SelectCommand="SELECT g.IDGruppo, g.Gruppo, g.Descrizione, g.Pubblicato, g.Ordine, g.NumeroClick, g.Url FROM Gruppi AS g ORDER BY g.Ordine">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsReport" runat="server" ConnectionString=""
        SelectCommand="SELECT gr.IDGruppo, r.IDReport, r.Titolo, r.IDTipoReport, r.Pubblicato, r.NumeroVisite, gr.Ordine FROM Report AS r INNER JOIN GruppiReport AS gr ON gr.IDReport = r.IDReport WHERE gr.IDGruppo = @IDGruppo">
        <SelectParameters>
            <asp:Parameter Type="Int32" Name="IDGruppo" /><asp:Parameter />
        </SelectParameters>
    </asp:SqlDataSource>
 
</asp:Content>

 

ConnectionString(s) are setted on the Init step:

 

namespace Stats.Secure
{
    public partial class ElencoGruppi : System.Web.UI.Page
    {
        string connDb;
 
        protected void Page_Init(object sender, EventArgs e)
        {
            // permesso solo per operatore
            if (Session["AuthIDRuolo"] != null && (int)Session["AuthIDRuolo"] >= 3)
            { }
            else
                Response.Redirect("Login.aspx?LOGOUT=1");
 
            // carica la stringa di connessione
            if (ConfigurationManager.AppSettings["appModoTest"] == "true")
                connDb = ConfigurationManager.ConnectionStrings["Stats.Test"].ConnectionString;
            else
                connDb = ConfigurationManager.ConnectionStrings["Stats"].ConnectionString;
 
            sdsGruppi.ConnectionString = connDb;
            sdsReport.ConnectionString = connDb;
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
 
    }
}

 

Thank you for advices.

8 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 15 Jan 2018, 03:09 PM

Hello,

I advise that you compare your setup with this demo and review the information from the demo description in detail: https://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarative-relations/defaultcs.aspx. Could you try renaming the fields in the SqlDataSource so they are not tableName.FieldName but only FieldName, as in our demo?

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Emanuele
Top achievements
Rank 1
Veteran
answered on 18 Jan 2018, 10:27 AM

Hi, I think the code reflects what is written on the page you suggested, which I had previously read.

Anyway I deleted references to the tables like you said. The second ds was based on a inner join and I had to replace it with a view that simplified it. But this did not solve the problem.

<asp:SqlDataSource ID="sdsGruppi" runat="server" ConnectionString=""
        SelectCommand="SELECT IDGruppo, Gruppo, Descrizione, Pubblicato, Ordine, NumeroClick, Url FROM Gruppi ORDER BY Ordine">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsReport" runat="server" ConnectionString=""
        SelectCommand="SELECT IDGruppo, IDReport, Titolo, IDTipoReport, Pubblicato, NumeroVisite FROM dev_report_gruppi WHERE IDGruppo = @IDGruppo">
        <SelectParameters>
            <asp:Parameter Type="Int32" Name="IDGruppo" /><asp:Parameter />
        </SelectParameters>
    </asp:SqlDataSource>

 

0
Emanuele
Top achievements
Rank 1
Veteran
answered on 19 Jan 2018, 04:23 PM

Could the behavior be affected by the lack of RadScriptManager and RadAjaxManager controls?

i don't inserted them in the page. 

but i changed the HierarchyLoadMode from "Cient" to "ServerOnDemand" wothout results.

0
Marin Bratanov
Telerik team
answered on 23 Jan 2018, 09:07 AM

Hello Emanuele,

To use IScriptControl instances (such as our controls) you must definitely have a script manager - either <telerik:RadScriptManager> or <asp:ScriptManager> at the beginning of the <form>, before any other controls.

A RadAjaxManager is not necessary, it facilitates partial page rendering like <asp:UpdatePanel> the control does, so it is not essential.

I am attaching here another example that also works fine. Could you try comparing that against what you get and see if this helps? If not, I advise that you open a ticket and send us a runnable example that illustrates the problem you have so we can offer a more concrete answer.

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Emanuele
Top achievements
Rank 1
Veteran
answered on 31 Jan 2018, 01:48 PM

Hi, 

i've made a little change on my code commenting some lines:

<asp:SqlDataSource ID="sdsReport" runat="server" ConnectionString=""<br>        SelectCommand="SELECT IDGruppo, IDReport, Titolo, IDTipoReport, Pubblicato, NumeroVisite FROM dev_report_gruppi "> <%--WHERE IDGruppo = @IDGruppo--%><br>        <%--<SelectParameters><br>            <asp:Parameter Type="Int32" Name="IDGruppo" /><asp:Parameter /><br>        </SelectParameters>--%><br>    </asp:SqlDataSource><br>

 

now, instead of having empty results, I get the whole table without filters for each parent row

 

i see your code, but it's quite different in datasources: 

in your case you have a big table and you give only a few records on the 1st level and on the 2nd level (detail) yoiu give all the records, is it right?
but I have 2 sets of different records linked by the IDgroup field

0
Marin Bratanov
Telerik team
answered on 01 Feb 2018, 12:56 PM

Hello Emanuele,

Perhaps I should have been clearer in my previous explanations. You can try binding the detail tables programmatically in a similar fashion to my example. The real code will not use a big hardcoded table, but will use your actual SQL table. You can see how to get the key from the parent item so you can use it in the query here: https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-raw-field-data-and-key-values.

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Emanuele
Top achievements
Rank 1
Veteran
answered on 05 Feb 2018, 01:42 PM

Hi, i've solved the first problem :-)

I left the first datasource for master grid; instead I have linked programmatically the data source of the detailsview

Now the code is 

<telerik:RadGrid ID="rgGruppi" runat="server" AllowSorting="True" AlternatingItemStyle-BackColor="#fff7e9" AutoGenerateColumns="False" RenderMode="Lightweight" Skin="Silk" Culture="it-IT" OnNeedDataSource="rgGruppi_NeedDataSource" OnDetailTableDataBind="rgGruppi_DetailTableDataBind">
    <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
 
    <ExportSettings>
        <Pdf PageWidth="">
        </Pdf>
    </ExportSettings>
 
    <AlternatingItemStyle BackColor="#FFF7E9"></AlternatingItemStyle>
 
    <MasterTableView EnableHierarchyExpandAll="true" DataKeyNames="IDGruppo" HierarchyLoadMode="Client" NoMasterRecordsText="Nessun dato trovato" AllowSorting="True">
        <DetailTables>
            <telerik:GridTableView EnableHierarchyExpandAll="true" DataKeyNames="IDReport" Width="100%" runat="server" NoDetailRecordsText="Nessun report trovato.">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="IDGruppo" MasterKeyField="IDGruppo"></telerik:GridRelationFields>
                </ParentTableRelation>
                <Columns>
                    <telerik:GridBoundColumn DataField="IDReport" HeaderText="ID" UniqueName="IDReport" DataType="System.Int32">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Titolo" HeaderText="Titolo" UniqueName="Titolo">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="IDTipoReport" HeaderText="Tipo" UniqueName="IDTipoReport">
                    </telerik:GridBoundColumn>
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>
            <telerik:GridBoundColumn DataField="IDGruppo" HeaderText="ID" UniqueName="IDGruppo" DataType="System.Int32">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Gruppo" HeaderText="Gruppo" UniqueName="Gruppo">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Descrizione" HeaderText="Descrizione" UniqueName="Descrizione">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn DataField="Pubblicato" HeaderText="Pubblicato" UniqueName="Pubblicato" DataType="System.Boolean">
            </telerik:GridCheckBoxColumn>
            <telerik:GridBoundColumn DataField="Ordine" HeaderText="Ordine" UniqueName="Ordine" DataType="System.Int32">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="NumeroClick" HeaderText="Click" UniqueName="NumeroClick" DataType="System.Int32" SortExpression="NumeroClick">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Url" HeaderText="Url" UniqueName="Url">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
 
    <FilterMenu RenderMode="Lightweight"></FilterMenu>
 
    <HeaderContextMenu RenderMode="Lightweight"></HeaderContextMenu>
</telerik:RadGrid>
 
<asp:SqlDataSource ID="sdsGruppi" runat="server" ConnectionString=""
    SelectCommand="SELECT IDGruppo, Gruppo, Descrizione, Pubblicato, Ordine, NumeroClick, Url FROM Gruppi ">    <%--ORDER BY Ordine--%>
</asp:SqlDataSource>
protected void rgGruppi_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    (sender as RadGrid).DataSource = sdsGruppi;
}
 
protected void rgGruppi_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
    // idgruppo selezionato
    int idg = (int)e.DetailTableView.ParentItem.GetDataKeyValue("IDGruppo");
 
    SqlConnection connessione = new SqlConnection(connDb);
    // variabili comuni
    SqlCommand comando = new SqlCommand();
    connessione.Open();
    comando.Connection = connessione;
    comando.CommandType = CommandType.Text;
 
    comando.Parameters.Clear();
    comando.CommandText = "SELECT IDGruppo, IDReport, Titolo, IDTipoReport, Pubblicato, NumeroVisite FROM dev_report_gruppi WHERE IDGruppo = @IDGruppo";
    comando.Parameters.Add("@IDGruppo", SqlDbType.Int).Value = idg;
 
    SqlDataAdapter daReports = new SqlDataAdapter(comando);
    DataTable dtReports = new DataTable();
    daReports.Fill(dtReports);
 
    //gvProdotti.DataSource = dtElenco;
    //gvProdotti.DataBind();
 
    e.DetailTableView.DataSource = dtReports;
}

Now i've to set the other behaviors. I need to order rows, but only details rows are running, the master rows are fixed: i press the header and the arrow reverses direction, but rows don't change their order. Nothing occurs if i specify a SortExpression properties for a field/column.

 

Thanks

0
Marin Bratanov
Telerik team
answered on 06 Feb 2018, 11:37 AM

Hi,

Could you try setting AllowMultiColumnSorting to true for the master table view, to mimic this demo: https://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarative-relations/defaultcs.aspx?

Also, since you are using the NeedDataSource event, I advise that you pass the DataSource to the main table programmatically as well, setting the DataSource property to the ID of a declarative data source should not produce proper results.

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Emanuele
Top achievements
Rank 1
Veteran
Answers by
Marin Bratanov
Telerik team
Emanuele
Top achievements
Rank 1
Veteran
Share this question
or