Is there a way to bind a simple Table or similar to...

G

Guest

a custom object. Similar to how I bind a collection of objects to a
repeater. Is there a way to bind a single object to a Table? I could use a
repeater, but seems over kill for a single object.

Thanks for any help.
 
E

Eliyahu Goldin

In the code-behind make a protected property that will go to the table and
derive the value you want to bind to. Bind to the property like this:

<td><%# SalesTotal %></td>

where SalesTotal is a protected property in the code-behind.

Eliyahu
 
G

Guest

I was hoping to bind to the table, ie. <table DataSource=<%# myobj %> then
use <td><%# DataBinder.Eval(Container.DataItem, "property")%>td>


Creating protected properties in the code behind for each property in my
object may be a hassle, but its an option. Perhaps I am missing something.
Just wondering if there is another way.

Thanks for your reply
 
E

Eliyahu Goldin

Ok, what you are after is binding a table rather than binding to the table.

No, an html table doesn't support DataSource. Instead you can do something
like
<table>
<asp:repeater ... DataSource= ...>
<asp:ItemTemplate>
<tr><td><%# DataBinder.Eval(Container.DataItem, "property")%></td></tr>
</asp:ItemTemplate>
</asp:repeater>
</table>

Eliyahu
 
G

Guest

Thats what I figured, but I was thinking a repeater might be over kill for a
single object, not a collection.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top