Problem with the datakeynames property of the listview component

Asked

Viewed 117 times

6

I get the following error when running the application:

Message=Databinding: 'Gesthos.Models.Documents.Fluxoapprovacaodocumento' does not contain a Property with the name 'Sector.Code'.

Error message refers to component ListView, on which property DataKeyNames is set as follows DataKeyNames="Codigo, Setor.Codigo".

The datasource of this ListView receives a list of objects of the type FluxoAprovacaoDocumento.

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

FluxoAprovacaoDocumento Setor

How to solve this problem?

<asp:ListView ID="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>
  • Have you tried anything else? Put the whole code of listview.

  • Não estou conseguindo colocar a parte inicial do código, segue: <asp:ListView ID="lstGerenciamento" DataKeyNames="Codigo, Setor.Codigo" runat="server" ItemPlaceholderID="itemPlaceholder" OnItemCommand="lstGerenciamento_ItemCommand" OnPagePropertiesChanged="lstGerenciamento_PagePropertiesChanged">

  • I haven’t tried anything else.

1 answer

2


The estate DataKeyNames does not support the use of sub-class properties. That is, in order to have this Codigo, will have to be in class FluxoAprovacaoDocumento.

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

public int SetorCodigo { 
  get { return Setor.Codigo; }
  set { Setor.Codigo = value; }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.