Problem with the datakeynames property of the listview component

6

I get the following error when running the application:

  

Message = DataBinding: 'DataMinds.Models.Focus.FlowerObject' does not contain a property with the 'Sector.Code' name.

The error message refers to the ListView component, where DataKeyNames property is set as DataKeyNames="Codigo, Setor.Codigo" .

The datasource of this ListView gets a list of objects of type FluxoAprovacaoDocumento .

The class FluxoAprovacaoDocumento , has a property of type Setor that has a property called Codigo .

HowdoIsolvethisproblem?

<asp:ListViewID="lstGerenciamento" DataKeyNames="Codigo, Setor.Codigo" runat="server" ItemPlaceholderID="itemPlaceholder" OnItemCommand="lstGerenciamento_ItemCommand" OnPagePropertiesChanged="lstGerenciamento_PagePropertiesChanged">
    <LayoutTemplate>
        <div class="table-responsive">
            <table class="table table-striped table-bordered table-condensed table-hover" runat="server" id="tblGerenciamento">
                <thead>
                     <tr class="title" runat="server">
                         <th runat="server">&nbsp;</th>
                         <th runat="server" class="text-right">Código</th>
                         <th runat="server">Setor</th>
                         <th runat="server">Tipo de Documento</th>
                         <th runat="server">Status</th>
                     </tr>
                </thead>
                <tbody>
                    <tr runat="server" id="itemPlaceholder" />
                </tbody>
            </table>
        </div>
    </LayoutTemplate>
    <ItemTemplate>
        <tr>
            <td class="col-md-1 text-center">
                <div class="btn-group">
                    <asp:LinkButton CssClass="btn btn-default btn-xs" data-toggle="tooltip" data-placement="bottom" title="Editar" ID="btnEditar" CommandName="Editar" runat="server" Visible='<%# Eval("AcessoMenu.IncluirAlterar").ToString().Equals("Sim") ? true : false %>'><span class="glyphicon glyphicon-edit"></span></asp:LinkButton>
                    <asp:LinkButton CssClass="btn btn-default btn-xs" data-toggle="tooltip" data-placement="bottom" title="Ver Detalhes" ID="btnDetalhes" CommandName="Detalhes" runat="server"><span class="glyphicon glyphicon-list-alt"></span></asp:LinkButton>
                    <asp:LinkButton CssClass="btn btn-default btn-xs" data-toggle="tooltip" data-placement="bottom" title="Excluir" ID="btnExcluir" CommandName="Excluir" runat="server" Visible='<%# Eval("AcessoMenu.IncluirAlterar").ToString().Equals("Sim") ? true : false %>'><span class="glyphicon glyphicon-trash"></span></asp:LinkButton>
                </div>
            </td>
            <td class="col-md-1  text-right" style="vertical-align: middle"><%# Eval("Codigo") %></td>
            <td class="col-md-3" style="vertical-align: middle"><%# string.Concat(Eval("Setor.Descricao"), " (", Eval("Setor.Sigla"), ")") %></td>
            <td class="col-md-4" style="vertical-align: middle"><%# string.Concat(Eval("TipoDocumento.Descricao"), " (", Eval("TipoDocumento.Sigla"), ")") %></td>
            <td class="col-md-1" style="vertical-align: middle"><%# Eval("Status") %></td>
        </tr>
    </ItemTemplate>
</asp:ListView>
    
asked by anonymous 26.08.2015 / 16:57

1 answer

2

The DataKeyNames property does not support the use of subclass properties. That is, in order to have this Codigo , it must be in the FluxoAprovacaoDocumento class.

You can create a property called SetorCodigo or something that simply returns Codigo of Setor :

public int SetorCodigo { 
  get { return Setor.Codigo; }
  set { Setor.Codigo = value; }
}
    
23.10.2015 / 17:36