Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
TempalteColumn in a DataGrid
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
TempalteColumn in a DataGrid
Miscellaneous
Thread ID:
00743625
Message ID:
00743625
Views:
48
Hi all,

I've run into somehting I can't seem to figure out. I have a datagrid bound to data from a dataset. The grid is loaded in Page_Load and all works well, until I add a template column that is supposed to access some data.

When I add a Tempalte Column which accesses data using the < % ERROR: # Container.DataItem("FieldName") % > I get the following error:

'System.Web.UI.WebControls.DataGridItem.DataItem' denotes a 'property' where a 'method' was expected

Here's the full grid. For argument's sake I've added the template column at the end since I was able to get what I wanted by using Hyperlink columns, but I still can't figure out why the template column doesn't work:
<asp:DataGrid id="dgItemList" runat="server" Width="90%" AutoGenerateColumns="false" CellPadding="3"
   BorderWidth="2px" CssClass="body" GridLines="Both">
   <AlternatingItemStyle CssClass="body" BackColor="#C0C0FF"></AlternatingItemStyle>
   <ItemStyle CssClass="body" BackColor="WhiteSmoke"></ItemStyle>
   <HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" CssClass="body" BackColor="Navy"></HeaderStyle>
   <Columns>
      <asp:HyperLinkColumn DataNavigateUrlField="sku" DataNavigateUrlFormatString="item.aspx?sku={0}" DataTextField="descript"
         HeaderText="Description"></asp:HyperLinkColumn>
      <asp:BoundColumn DataField="Price" HeaderText="Price" DataFormatString="{0:F}">
         <HeaderStyle HorizontalAlign="Right" Width="50px"></HeaderStyle>
         <ItemStyle HorizontalAlign="Right"></ItemStyle>
      </asp:BoundColumn>
      <asp:HyperLinkColumn DataNavigateUrlField="sku" DataNavigateUrlFormatString="additem.aspx?sku={0}" Text="Add"
         HeaderText="Buy">
         <ItemStyle HorizontalAlign="Center"></ItemStyle>
      </asp:HyperLinkColumn>
<b>      <asp:TemplateColumn HeaderText="Buy">
         <ItemStyle HorizontalAlign="Center" Width="50px"></ItemStyle>
         <ItemTemplate>
            <%# Container.DataItem("sku") %> -
            <%# Container.DataItem("descript") %>
         </ItemTemplate>
      </asp:TemplateColumn></b>
   </Columns>
</asp:DataGrid>
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Next
Reply
Map
View

Click here to load this message in the networking platform