Urgent! GridView and templated controls binding. Plz help

S

Shafia

Hi,

My GridView has templated controls in it and I'm binding to an
ObjectDataSource. The problem is it refused to bind to my grid column
"ColumnName" which is also an UpdateCommand Parameter for the
ObjectDataSource. It displays the following error
"DataBinding: 'System.String' does not contain a property with the name
'ColumnName'.
I've also cheched it with FormView and that is not binding either. same
error.

<ItemTemplate>

<asp:Label ID="Label5" runat="server" Text='<%# Eval("ColumnName")
%>'></asp:Label>

</ItemTemplate>



Plz help,

Shafia
 
M

Matt

Shouldn't the databinding expression look more like:

<%# DataBinder.Eval(Container.DataItem, "Column") %>

or if you want to cast the object to its type (if you're using a
collection say)

<%# ((MyObjectType)Container.DataItem).PropertyName.ToString() %>
 
S

Shafia

Hi,

Please let me know what is the container supposed to be
is this correct?


<%# DataBinder.Eval(Label5.Text, "MyColumn") %>

where Label5 is a Label control on a Column Template for GridView. It
gives me compilation error
Label5 can not be refencened in this context

Thanks
 
M

Matt

DataBinder.Eval and Container.DataItem are literally correct:

<ItemTemplate>
<asp:Label id="Label5" runat="server" Text="<%#
DataBinder.Eval(Container.Data­Item, "MyColumn") %>"></asp:Label>
</ItemTemplate>
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top