Databind a label outside of clasic data controls (DataList, Repeater, GridView, etc)

Discussion in 'ASP .Net' started by craigkenisston@hotmail.com, Sep 15, 2006.

  1. Guest

    In Asp.Net 2.0 I need to create a very special layout with data coming
    from an ObjectDataSource.
    It was already working using a GridView, but I need a free layout.
    So, I dropped the GridView and added something like this:

    So, I'm trying something like :
    <div>
    <table>
    <tr>
    <td>
    Referring URL:</td>
    <td>
    <asp:label id="lblReferringURL" runat="server"
    text='<%# DataBinder.Eval(ObjectDataSource1, "CTRY_CODE") %>'>
    </asp:label>
    </td>
    </tr>
    <tr>
    <td>
    Entry Page:</td>
    <td>
    <asp:label id="lblEntryPage" runat="server" text='<%#
    DataBinder.Eval(ObjectDataSource1, "STAT_CODE") %>'></asp:label>
    </td>
    </tr>
    </table>
    </div>

    Then I used Page.DataBind() in code behind.
    I got errors telling me that there are no objects "CTRY_CODE" or
    "STAT_CODE" in ObjectDataSource1.

    What's the proper way to do this ?
     
    , Sep 15, 2006
    #1
    1. Advertising

  2. Hi,

    How about using a templated FormView and then bind the FormView to the
    objectdatasource. Something like this:

    <asp:formview id="FormView1" runat="server"
    datasourceid="ObjectDataSource1">
    <itemtemplate>
    <div>
    <table>
    <tr>
    <td>Referring URL:</td>
    <td>
    <asp:label id="lblReferringURL"
    runat="server" text='<%# Eval("CTRY_CODE") %>'>
    </asp:label>
    </td>
    </tr>
    <tr>
    <td>Entry Page:</td>
    <td>
    <asp:label id="lblEntryPage"
    runat="server" text='<%# Eval("STAT_CODE") %>'></asp:label>
    </td>
    </tr>
    </table>
    </div>
    </itemtemplate>
    </asp:formview>

    Not sure this is what you're after, but thought I'd suggest it.

    Ken
    Microsoft MVP [ASP.NET]


    <> wrote in message
    news:...
    > In Asp.Net 2.0 I need to create a very special layout with data coming
    > from an ObjectDataSource.
    > It was already working using a GridView, but I need a free layout.
    > So, I dropped the GridView and added something like this:
    >
    > So, I'm trying something like :
    > <div>
    > <table>
    > <tr>
    > <td>
    > Referring URL:</td>
    > <td>
    > <asp:label id="lblReferringURL" runat="server"
    > text='<%# DataBinder.Eval(ObjectDataSource1, "CTRY_CODE") %>'>
    > </asp:label>
    > </td>
    > </tr>
    > <tr>
    > <td>
    > Entry Page:</td>
    > <td>
    > <asp:label id="lblEntryPage" runat="server" text='<%#
    > DataBinder.Eval(ObjectDataSource1, "STAT_CODE") %>'></asp:label>
    > </td>
    > </tr>
    > </table>
    > </div>
    >
    > Then I used Page.DataBind() in code behind.
    > I got errors telling me that there are no objects "CTRY_CODE" or
    > "STAT_CODE" in ObjectDataSource1.
    >
    > What's the proper way to do this ?
    >
     
    Ken Cox [Microsoft MVP], Sep 15, 2006
    #2
    1. Advertising

  3. Guest

    Thank you !


    Ken Cox [Microsoft MVP] wrote:
    > Hi,
    >
    > How about using a templated FormView and then bind the FormView to the
    > objectdatasource. Something like this:
    >
    > <asp:formview id="FormView1" runat="server"
    > datasourceid="ObjectDataSource1">
    > <itemtemplate>
    > <div>
    > <table>
    > <tr>
    > <td>Referring URL:</td>
    > <td>
    > <asp:label id="lblReferringURL"
    > runat="server" text='<%# Eval("CTRY_CODE") %>'>
    > </asp:label>
    > </td>
    > </tr>
    > <tr>
    > <td>Entry Page:</td>
    > <td>
    > <asp:label id="lblEntryPage"
    > runat="server" text='<%# Eval("STAT_CODE") %>'></asp:label>
    > </td>
    > </tr>
    > </table>
    > </div>
    > </itemtemplate>
    > </asp:formview>
    >
    > Not sure this is what you're after, but thought I'd suggest it.
    >
    > Ken
    > Microsoft MVP [ASP.NET]
    >
    >
    > <> wrote in message
    > news:...
    > > In Asp.Net 2.0 I need to create a very special layout with data coming
    > > from an ObjectDataSource.
    > > It was already working using a GridView, but I need a free layout.
    > > So, I dropped the GridView and added something like this:
    > >
    > > So, I'm trying something like :
    > > <div>
    > > <table>
    > > <tr>
    > > <td>
    > > Referring URL:</td>
    > > <td>
    > > <asp:label id="lblReferringURL" runat="server"
    > > text='<%# DataBinder.Eval(ObjectDataSource1, "CTRY_CODE") %>'>
    > > </asp:label>
    > > </td>
    > > </tr>
    > > <tr>
    > > <td>
    > > Entry Page:</td>
    > > <td>
    > > <asp:label id="lblEntryPage" runat="server" text='<%#
    > > DataBinder.Eval(ObjectDataSource1, "STAT_CODE") %>'></asp:label>
    > > </td>
    > > </tr>
    > > </table>
    > > </div>
    > >
    > > Then I used Page.DataBind() in code behind.
    > > I got errors telling me that there are no objects "CTRY_CODE" or
    > > "STAT_CODE" in ObjectDataSource1.
    > >
    > > What's the proper way to do this ?
    > >
     
    , Sep 16, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Prabhat Nath

    Clasic ASP Connection String

    Prabhat Nath, Mar 10, 2005, in forum: ASP .Net
    Replies:
    12
    Views:
    14,902
    Prabhat
    Mar 11, 2005
  2. Eric
    Replies:
    2
    Views:
    413
  3. Nathan Truhan

    Staggering Data using DataList, Repeater, etc...

    Nathan Truhan, May 13, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    127
    Steve Goodyear
    May 15, 2005
  4. Prabhat

    Clasic ASP Connection String

    Prabhat, Mar 10, 2005, in forum: ASP General
    Replies:
    4
    Views:
    156
    Prabhat
    Mar 11, 2005
  5. Knut Krueger
    Replies:
    8
    Views:
    280
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page