Urgent! GridView and templated controls binding. Plz help

Discussion in 'ASP .Net Building Controls' started by Shafia, Apr 13, 2005.

  1. Shafia

    Shafia Guest


    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
    I've also cheched it with FormView and that is not binding either. same


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


    Plz help,

    Shafia, Apr 13, 2005
    1. Advertisements

  2. Shafia

    Matt Guest

    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() %>
    Matt, Apr 13, 2005
    1. Advertisements

  3. Shafia

    Shafia Guest


    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

    Shafia, Apr 14, 2005
  4. Shafia

    Matt Guest

    DataBinder.Eval and Container.DataItem are literally correct:

    <asp:Label id="Label5" runat="server" Text="<%#
    DataBinder.Eval(Container.Data­Item, "MyColumn") %>"></asp:Label>
    Matt, Apr 14, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.