DataGrid - Template Columns

  • Thread starter André Almeida Maldonado
  • Start date
A

André Almeida Maldonado

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
 
C

Craig Deelsnyder

André Almeida Maldonado said:
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....
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top