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

  • Thread starter Thread starter craigkenisston
  • Start date Start date
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 ?
 
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]
 
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 ?
 
Back
Top