DataGrid - Template Columns

Discussion in 'ASP .Net' started by André Almeida Maldonado, Jan 13, 2004.

  1. Hy Guys..

    I have a datagrid with template columns. The datagrid have a datatable
    datasource. But when I try to bind data, I receive this error:

    DataBinder.Eval: 'System.Web.UI.WebControls.DataGridItem' do not have a
    property named "Codigo".

    See my code:

    <asp:TemplateColumn HeaderText="Código">
    <HeaderStyle HorizontalAlign="Justify" Width="80px"
    CssClass="grid-header" VerticalAlign="Middle"></HeaderStyle>
    <ItemStyle HorizontalAlign="Justify"></ItemStyle>
    <ItemTemplate>
    <asp:label ID="item_lblPediGrCo" Text=' <%#
    DataBinder.Eval(Container, "Codigo") %>' Runat="server" Width='80px' />
    </ItemTemplate>
    <EditItemTemplate>
    <asp:label ID="edit_lblPediGrCo" Text='' Runat="server" Width='80px'
    />
    </EditItemTemplate>
    </asp:TemplateColumn>

    <asp:TemplateColumn HeaderText="Produto">
    <HeaderStyle HorizontalAlign="Justify" Width="80px"
    CssClass="grid-header" VerticalAlign="Middle"></HeaderStyle>
    <ItemStyle HorizontalAlign="Justify"></ItemStyle>
    <ItemTemplate>
    <asp:label ID="item_lblPediGrPr" Text=' <%#
    DataBinder.Eval(Container, "Produto") %>' Runat="server" Width='80px' />
    </ItemTemplate>
    <EditItemTemplate>
    <asp:dropdownlist Width="80px" ID="edit_drpPediGrPr"
    CssClass="Standard-text" DataSource='<%# drppediprod %>' Runat="server">
    </asp:dropdownlist>
    </EditItemTemplate>
    </asp:TemplateColumn>


    Where is the error????

    Thank's
    André Almeida Maldonado, Jan 13, 2004
    #1
    1. Advertising

  2. André Almeida Maldonado wrote:

    > Hy Guys..
    >
    > DataBinder.Eval: 'System.Web.UI.WebControls.DataGridItem' do not have a
    > property named "Codigo".
    >
    > See my code:
    >
    > <asp:TemplateColumn HeaderText="Código">
    > <HeaderStyle HorizontalAlign="Justify" Width="80px"
    > CssClass="grid-header" VerticalAlign="Middle"></HeaderStyle>
    > <ItemStyle HorizontalAlign="Justify"></ItemStyle>
    > <ItemTemplate>
    > <asp:label ID="item_lblPediGrCo" Text=' <%#
    > DataBinder.Eval(Container, "Codigo") %>' Runat="server" Width='80px' />


    >
    > Where is the error????
    >
    > Thank's
    >
    >


    try
    DataBinder.Eval(Container.DataItem, "Codigo")

    instead of
    DataBinder.Eval(Container, "Codigo")
    the Container is the DataGrid itself, so you have to reference .DataItem
    to get that item's data in the datasource....

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
    Craig Deelsnyder, Jan 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    4
    Views:
    584
    Felix Wu [MSFT]
    Jul 9, 2003
  2. Nicole
    Replies:
    2
    Views:
    4,509
    Nicole
    Nov 5, 2003
  3. rob thomson
    Replies:
    0
    Views:
    253
    rob thomson
    Sep 4, 2003
  4. ton
    Replies:
    2
    Views:
    200
    Alvin Bruney [MVP]
    Feb 11, 2004
  5. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    843
    Vinki
    Apr 25, 2007
Loading...

Share This Page