Urgent! GridView and templated controls binding. Plz help

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

  1. Shafia

    Shafia Guest

    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
     
    Shafia, Apr 13, 2005
    #1
    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
    #2
    1. Advertisements

  3. Shafia

    Shafia Guest

    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
     
    Shafia, Apr 14, 2005
    #3
  4. Shafia

    Matt Guest

    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>
     
    Matt, Apr 14, 2005
    #4
    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.