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

C

craigkenisston

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 ?
 
K

Ken Cox [Microsoft MVP]

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]
 
C

craigkenisston

Thank you !

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]


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 ?
 

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,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top