DataGrid - Template Columns

  • Thread starter Thread starter André Almeida Maldonado
  • Start date 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
 
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....
 
Back
Top