Is there an ASP.NET databindable control (like Repeater), which only expects a single item?

NickG

I'm trying display lots of properties from a business object on a Web Form. I could of course, create loads of labels and assign all the values in code-behind, but I feel there must be a less verbose way.

What I want is something like an asp:Panel but where you can specify a datasource. It doesn't seem like Panels support any kind of databinding.

What I'd like is something like this

// C#
panel.DataSource = theCompany;
panel.DataBind();

Then:

// ASPX

<asp:Panel runat="server">
    Name: <%# Eval("Name") %>
    Phone: <%# Eval("Phone") %> 
    ...
</asp:Panel>

..but I can't find anything which will allow me to work in this way.

I thought I might be able to use asp:FormView but this just gives the error "Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource."

A caveat is that I do not want to call a global DataBind() (this has caused us no-end of problems in the past) - I would like the databind to be constrained to a particular part of the page.

NickG

It seems you can do this using a Panel, but you have to assign your business object to a page property first, as there's no way to set the business object as a "DataSource" for the panel (as you would for a Repeater control, for instance).

Once the object is assigned as a page property, you can then use the following syntax in the .aspx to access the properties of that object, without needing to manually assign each item to control values in code behind:

<%# Company.Name %>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is there an ASP.NET databindable control (like Repeater), which only expects a single item?

From Dev

How can I bind the single LINQ object to ASP.NET Repeater Control

From Dev

repeater item command in asp.net

From Dev

ASP.NET Converting repeater item to the textbox

From Dev

ASP.NET repeater only renders the first item in my XML data source

From Dev

Condition in ASP Repeater Control

From Dev

ASP.NET Repeater Control - Getting Hiddenfield value inside the repeater control

From Dev

ASP.NET Repeater Control - Getting Hiddenfield value inside the repeater control

From Dev

How to use paging with Repeater control in ASP.NET?

From Dev

How to dynamically bind asp.net repeater control to datasource

From Dev

Performing mathematical calculations inside asp.net repeater control

From Dev

ASP.NET user control property in a repeater is null after postback

From Dev

ASP.Net repeater control - using conditional statements

From Dev

css template for image repeater control in asp.net

From Dev

How to dynamically bind asp.net repeater control to datasource

From Dev

.NET 4.5, LINQ, Bootstrap tab control, and asp:Repeater

From Dev

how to count value of last column in repeater control in asp.net

From Dev

ASP.NET: Table with Repeater control and alternating data in same for

From Dev

jQuery is not finding Asp.net repeater alternating item

From Dev

ASP.NET Repeater Item add divider after each row

From Dev

Show/Hide Single Row in ASP.NET Repeater

From Dev

Focus to a particular repeater control item

From Dev

button click event in repeater control to show data in same repeater in asp.net c#

From Dev

ASP Repeater control with multiple templates

From Dev

how to align repeater control item template content

From Dev

Adding a control to repeater item template programmatically

From Dev

Which repeater item did I just affect?

From Dev

NavigateUrl on Repeater ASP.net

From Dev

NavigateUrl on Repeater ASP.net

Related Related

  1. 1

    Is there an ASP.NET databindable control (like Repeater), which only expects a single item?

  2. 2

    How can I bind the single LINQ object to ASP.NET Repeater Control

  3. 3

    repeater item command in asp.net

  4. 4

    ASP.NET Converting repeater item to the textbox

  5. 5

    ASP.NET repeater only renders the first item in my XML data source

  6. 6

    Condition in ASP Repeater Control

  7. 7

    ASP.NET Repeater Control - Getting Hiddenfield value inside the repeater control

  8. 8

    ASP.NET Repeater Control - Getting Hiddenfield value inside the repeater control

  9. 9

    How to use paging with Repeater control in ASP.NET?

  10. 10

    How to dynamically bind asp.net repeater control to datasource

  11. 11

    Performing mathematical calculations inside asp.net repeater control

  12. 12

    ASP.NET user control property in a repeater is null after postback

  13. 13

    ASP.Net repeater control - using conditional statements

  14. 14

    css template for image repeater control in asp.net

  15. 15

    How to dynamically bind asp.net repeater control to datasource

  16. 16

    .NET 4.5, LINQ, Bootstrap tab control, and asp:Repeater

  17. 17

    how to count value of last column in repeater control in asp.net

  18. 18

    ASP.NET: Table with Repeater control and alternating data in same for

  19. 19

    jQuery is not finding Asp.net repeater alternating item

  20. 20

    ASP.NET Repeater Item add divider after each row

  21. 21

    Show/Hide Single Row in ASP.NET Repeater

  22. 22

    Focus to a particular repeater control item

  23. 23

    button click event in repeater control to show data in same repeater in asp.net c#

  24. 24

    ASP Repeater control with multiple templates

  25. 25

    how to align repeater control item template content

  26. 26

    Adding a control to repeater item template programmatically

  27. 27

    Which repeater item did I just affect?

  28. 28

    NavigateUrl on Repeater ASP.net

  29. 29

    NavigateUrl on Repeater ASP.net

HotTag

Archive