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

I would recommend changing your databinding syntax to the following:
<%# DataBinder.Eval(Container.DataItem,"sku") % >
>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>
>            < % ERROR: # Container.DataItem("sku")  % > -
>            < % ERROR: # Container.DataItem("descript")  % >
>         </ItemTemplate>
>      </asp:TemplateColumn></b>
>   </Columns>
></asp:DataGrid>
>
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform