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

NestedViewTemplate and DataBinding error

2 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luca Di Leo
Top achievements
Rank 1
Luca Di Leo asked on 11 Jun 2010, 01:49 AM
Hi all,

I have a very complex page with many sub-levels of hierarchy and I'm encountering some problems on a NestedViewTemplate binding:

System.Web.HttpException was unhandled by user code
  Message=DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Domicilio'.
  Source=System.Web
  ErrorCode=-2147467259
  WebEventCode=0
 
Here is the code of the problematic level:

<telerik:GridTableView runat="server" AutoGenerateColumns="False" Caption="Elenco Dipendenti" 
                            CommandItemDisplay="Bottom" DataKeyNames="DipendentiID" DataSourceID="SqlDipendentiSource" 
                            AllowSorting="False" EditMode="PopUp" Name="DipendentiView" NoDetailRecordsText="Nessun dipendente per la sede corrente."
                            <CommandItemSettings AddNewRecordText="Aggiungi Dipendente" ShowRefreshButton="False" /> 
                            <Columns> 
                                <telerik:GridButtonColumn ButtonType="ImageButton" UniqueName="DipendentiEditCommandColumn" 
                                    CommandName="Edit" HeaderStyle-Width="30px"
                                    <HeaderStyle Width="30px"></HeaderStyle> 
                                    <ItemStyle CssClass="MyImageButton" /> 
                                </telerik:GridButtonColumn> 
                                <telerik:GridButtonColumn ButtonType="ImageButton" UniqueName="DipendentiDeleteCommandColumn" 
                                    CommandName="Delete" HeaderStyle-Width="30px"
                                    <HeaderStyle Width="30px"></HeaderStyle> 
                                    <ItemStyle CssClass="MyImageButton" /> 
                                </telerik:GridButtonColumn> 
                                <telerik:GridBoundColumn DataField="DipendentiID" HeaderText="ID" SortExpression="DipendentiID" 
                                    UniqueName="DipendentiID" DataType="System.Int32" ReadOnly="True" HeaderStyle-Width="35px" 
                                    HeaderStyle-HorizontalAlign="Center" AllowFiltering="False"
                                    <HeaderStyle HorizontalAlign="Center" Width="35px"></HeaderStyle> 
                                    <ItemStyle HorizontalAlign="Center" /> 
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="Nome" HeaderText="Nome" UniqueName="Nome" DataType="System.String" 
                                    ReadOnly="True" HeaderStyle-HorizontalAlign="Center" AllowFiltering="True"
                                    <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
                                    <ItemStyle HorizontalAlign="Center" /> 
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="Cognome" HeaderText="Cognome" UniqueName="Cognome" 
                                    DataType="System.String" ReadOnly="True" HeaderStyle-HorizontalAlign="Center" 
                                    AllowFiltering="True"
                                    <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
                                    <ItemStyle HorizontalAlign="Center" /> 
                                </telerik:GridBoundColumn> 
                                <telerik:GridTemplateColumn UniqueName="Sesso" InitializeTemplatesFirst="false" HeaderStyle-HorizontalAlign="Center" 
                                    AllowFiltering="false"
                                    <HeaderTemplate> 
                                        Sesso 
                                    </HeaderTemplate> 
                                    <ItemTemplate> 
                                        <%# (((bool)Eval("Sesso")) ? "M" : "F") %> 
                                    </ItemTemplate> 
                                    <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
                                </telerik:GridTemplateColumn> 
                                <telerik:GridBoundColumn DataField="DataAssunzione" HeaderText="Data di Assunzione" 
                                    UniqueName="DataAssunzione" DataType="System.DateTime" ReadOnly="True" HeaderStyle-HorizontalAlign="Center" 
                                    AllowFiltering="True"
                                    <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
                                    <ItemStyle HorizontalAlign="Center" /> 
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="DataLicenziamento" HeaderText="Data di Licenziamento" 
                                    UniqueName="DataLicenziamento" DataType="System.DateTime" ReadOnly="True" HeaderStyle-HorizontalAlign="Center" 
                                    AllowFiltering="True"
                                    <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
                                    <ItemStyle HorizontalAlign="Center" /> 
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn DataField="Telefono" HeaderText="Telefono" UniqueName="Telefono" 
                                    DataType="System.String" ReadOnly="True" HeaderStyle-HorizontalAlign="Center" 
                                    AllowFiltering="False"
                                    <HeaderStyle HorizontalAlign="Center"></HeaderStyle> 
                                    <ItemStyle HorizontalAlign="Center" /> 
                                </telerik:GridBoundColumn> 
                            </Columns> 
                            <RowIndicatorColumn> 
                                <HeaderStyle Width="20px" /> 
                            </RowIndicatorColumn> 
                            <ExpandCollapseColumn> 
                                <HeaderStyle Width="20px" /> 
                            </ExpandCollapseColumn> 
                            <ParentTableRelation> 
                                <telerik:GridRelationFields DetailKeyField="SediID" MasterKeyField="SediID" /> 
                            </ParentTableRelation> 
                            <NestedViewSettings DataSourceID="SqlDipendentiExtendedSource"
                                <ParentTableRelation> 
                                    <telerik:GridRelationFields DetailKeyField="DipendentiID" MasterKeyField="DipendentiID" /> 
                                </ParentTableRelation> 
                            </NestedViewSettings> 
                            <NestedViewTemplate> 
                                <asp:Panel ID="NestedViewDipendentiPanel" runat="server"
                                    <div> 
                                        <fieldset style="padding: 10px;"
                                            <legend style="padding: 5px;">Dettagli su: <b> 
                                                <%# Eval("Nome") %> 
                                                <%# Eval("Cognome") %></b></legend> 
                                            <table width="50%"
                                                <tr> 
                                                    <td> 
                                                        Nome: 
                                                    </td> 
                                                    <td> 
                                                        <%# Eval("Nome") %> 
                                                    </td> 
                                                </tr> 
                                                <tr> 
                                                    <td> 
                                                        Cognome: 
                                                    </td> 
                                                    <td> 
                                                        <%# Eval("Cognome") %> 
                                                    </td> 
                                                </tr> 
                                                <tr> 
                                                    <td> 
                                                        Sesso: 
                                                    </td> 
                                                    <td> 
                                                        <%# (((bool)Eval("Sesso")) ? "Maschio" : "Femmina")%> 
                                                    </td> 
                                                </tr> 
                                                <tr> 
                                                    <td> 
                                                        Telefono: 
                                                    </td> 
                                                    <td> 
                                                        <%# Eval("Telefono")%> 
                                                    </td> 
                                                </tr> 
                                                <tr> 
                                                    <td> 
                                                        Domicilio: 
                                                    </td> 
                                                    <td> 
                                                        <%# Eval("Domicilio") %> 
                                                    </td> 
                                                </tr> 
                                                <tr> 
                                                    <td> 
                                                        Residenza: 
                                                    </td> 
                                                    <td> 
                                                        <%# Eval("Residenza") %> 
                                                    </td> 
                                                </tr> 
                                                <tr> 
                                                    <td> 
                                                        Residenza: 
                                                    </td> 
                                                    <td> 
                                                        <%# Eval("Nascita") %> 
                                                    </td> 
                                                </tr> 
                                                <tr> 
                                                    <td> 
                                                        Data di Assunzione: 
                                                    </td> 
                                                    <td> 
                                                        <%# Eval("DataAssunzione") %> 
                                                    </td> 
                                                </tr> 
                                                <tr> 
                                                    <td> 
                                                        Data di Licenziamento: 
                                                    </td> 
                                                    <td> 
                                                        <%# ((Eval("DataLicenziamento") is DBNull) ? "Nessuna" : Eval("DataLicenziamento")) %> 
                                                    </td> 
                                                </tr> 
                                            </table> 
                                        </fieldset> 
                                    </div> 
                                </asp:Panel> 
                            </NestedViewTemplate> 
                            <EditFormSettings EditFormType="Template"
                                <FormTemplate> 
                                </FormTemplate> 
                            </EditFormSettings> 
                        </telerik:GridTableView> 

I use 2 SqlDataSources:

    <asp:SqlDataSource ID="SqlDipendentiSource" runat="server" ConnectionString="<%$ ConnectionStrings:ReleaseConnection %>" 
        SelectCommand="SELECT ML.Dipendenti.id AS DipendentiID, ML.Dipendenti.Nome, ML.Dipendenti.Cognome, ML.Dipendenti.Sesso, ML.Dipendenti.DataAssunzione, ML.Dipendenti.DataLicenziamento, ML.Dipendenti.Telefono, LocalitaPaesi.Via + ' ' + LocalitaPaesi.Numero + ', ' + LocalitaPaesi.NomeComune + ' (' + LocalitaPaesi.ProvinciaSigla + ') ' + LocalitaPaesi.PaeseSigla AS Residenza FROM ML.Dipendenti INNER JOIN LocalitaPaesi ON ML.Dipendenti.LuogoResidenza = LocalitaPaesi.id WHERE (ML.Dipendenti.Sede = @SediID)"
        <SelectParameters> 
            <asp:Parameter Name="SediID" Type="Int32" /> 
        </SelectParameters> 
    </asp:SqlDataSource> 
 

and

    <asp:SqlDataSource ID="SqlDipendentiExtendedSource" runat="server" ConnectionString="<%$ ConnectionStrings:ReleaseConnection %>" 
        SelectCommand="SELECT ML.Dipendenti.id AS DipendentiID, ML.Dipendenti.Nome, ML.Dipendenti.Cognome, ML.Dipendenti.Sesso, ML.Dipendenti.DataAssunzione, ML.Dipendenti.DataLicenziamento, ML.Dipendenti.DataNascita, ML.Dipendenti.Telefono, LocalitaPaesiDomicilio.Via + ' ' + LocalitaPaesiDomicilio.Numero + ', ' + LocalitaPaesiDomicilio.NomeComune + ' (' + LocalitaPaesiDomicilio.ProvinciaSigla + ') ' + LocalitaPaesiDomicilio.PaeseSigla AS Domicilio, LocalitaPaesiLuogoResidenza.Via + ' ' + LocalitaPaesiLuogoResidenza.Numero + ', ' + LocalitaPaesiLuogoResidenza.NomeComune + ' (' + LocalitaPaesiLuogoResidenza.ProvinciaSigla + ') ' + LocalitaPaesiLuogoResidenza.PaeseSigla AS Residenza, LocalitaPaesiLuogoNascita.Via + ' ' + LocalitaPaesiLuogoNascita.Numero + ', ' + LocalitaPaesiLuogoNascita.NomeComune + ' (' + LocalitaPaesiLuogoNascita.ProvinciaSigla + ') ' + LocalitaPaesiLuogoNascita.PaeseSigla AS Nascita, ML.Medici.Nome AS NomeMedico, ML.Medici.Cognome AS CognomeMedico, ML.Medici.Telefono AS TelefonoMedico, LocalitaMedico.Via + ' ' + LocalitaMedico.Numero + ', ' + LocalitaMedico.NomeComune + ' (' + LocalitaMedico.ProvinciaSigla + ') ' + LocalitaMedico.PaeseSigla AS LocalitaMedico FROM ML.Dipendenti INNER JOIN LocalitaPaesi AS LocalitaPaesiDomicilio ON ML.Dipendenti.LuogoResidenza = LocalitaPaesiDomicilio.id INNER JOIN LocalitaPaesi AS LocalitaPaesiLuogoNascita ON ML.Dipendenti.LuogoNascita = LocalitaPaesiLuogoNascita.id INNER JOIN LocalitaPaesi AS LocalitaPaesiLuogoResidenza ON ML.Dipendenti.LuogoResidenza = LocalitaPaesiLuogoResidenza.id INNER JOIN ML.TitoliStudio ON ML.Dipendenti.TitoloStudio = ML.TitoliStudio.id INNER JOIN ML.Medici ON ML.Dipendenti.Medico = ML.Medici.id INNER JOIN LocalitaPaesi AS LocalitaMedico ON ML.Medici.Locazione = LocalitaMedico.id WHERE (ML.Dipendenti.id = @DipendentiID)"
        <SelectParameters> 
            <asp:Parameter Name="DipendentiID" Type="Int32" /> 
        </SelectParameters> 
    </asp:SqlDataSource> 
 

I know that those queries can be optimized/reduced and DataGrid layout/paging is actually like "out of the box", but I'm very short of time :(

It seems that DataBinder cannot find SqlDipendentiExtendedSource field but only SqlDipendentiSource ones... how can it be?

thanks in advance for you help!

2 Answers, 1 is accepted

Sort by
0
Luca Di Leo
Top achievements
Rank 1
answered on 11 Jun 2010, 09:13 AM
up
0
Yavor
Telerik team
answered on 16 Jun 2010, 12:13 PM
Hi Luca,

I reviewed the code, and it looks correct. If the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and get back to you with more information on the matter.

Sincerely yours,
Yavor
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Luca Di Leo
Top achievements
Rank 1
Answers by
Luca Di Leo
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or