DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Fri, 17 Aug 2007 05:50:00 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Alex Maghen am
          2    (Steven Cheng[MSFT])


ObjectList Data-Binding to a List<MyClass>   
Let's say I have defined a class:

    public class TestClass
    {
        int m_ID;
        string m_UserTitle;

        public TestClass(int ID, string UserTitle)
        {
            m_ID = ID;
            m_UserTitle = UserTitle;
        }

        public int ID
        {
            get
            {
                return (m_ID);
            }
        }
        public string UserTitle
        {
            get
            {
                return (m_UserTitle);
            }
        }
    }


Now I want to display it using an ObjectList, so I do this on my ASPX page...

<mobile:ObjectList ID="OL" Runat="server" 
    CommandStyle-StyleReference="subcommand" AutoGenerateFields="False" 
    LabelStyle-StyleReference="title">
    <DeviceSpecific>
        <Choice>
            <ItemDetailsTemplate>
                <mobile:Label ID="Label4" Runat="server"><%# Eval("ID") 
%></mobile:Label> 
                <mobile:Label ID="Label2" Runat="server"><%# 
Eval("UserTitle") %></mobile:Label>
                <mobile:Image ID="Image2" Runat="server" 
                    
ImageUrl="http://www.asp.net/App_Themes/Standard/i/logo.png"></mobile:Image>
            </ItemDetailsTemplate>
        </Choice>
    </DeviceSpecific>
</mobile:ObjectList>


NOW, back in my page code, I do this...

private void DisplayList()
{

    List<TestClass> L = new List<TestClass>();

    L.Add(new TestClass(1, "UserTitle 1"));
    L.Add(new TestClass(2, "UserTitle 2"));
    
    OL.DataSource = L;
    OL.DataBind(); //RUNTIME ERROR HAPPENS HERE!
}

Note that I am trying to configure this control to only have one template 
which will be very VERY simple and should work for all devices.

When I have done all this, I get a runtime error on the DataBind() line as 
follows...

System.Exception was unhandled by user code
  Message="Must have one or more fields to databind.
  (Application may have autogenerated fields from an empty DataSource.  To 
clear items, set DataSource to null.)"


Any ideas what I'm doign wrong here?

Thanks!

Alex
Date:Fri, 17 Aug 2007 05:50:00 -0700   Author:  

RE: ObjectList Data-Binding to a List<MyClass>   
Hi Alex,

Seems this is a continual post from a former thread discussing on "Mobile 
Repeater", correct?

I've performed test through the code you provided and did met the error you 
said. After some research, I found that the error is caused by no data 
fields are defined in the ObjectList control. Actually, if you turn off 
"AutoGenerateFields" in ObjectList, you need to supply the fields you want 
to use in your ObjectList. You should use the <Field > element to add 
fields definition into the ObjectList. 

For your "TestClass" scenario, here is the expected ObjectList aspx 
template:

================
        <mobile:ObjectList ID="ObjectList1" Runat="server" 
CommandStyle-StyleReference="subcommand"
            LabelStyle-StyleReference="title" AutoGenerateFields="False" 
LabelField="UserTitle"   >
           
          <DeviceSpecific ID="ds_ol1" Runat="server">
          
          <Choice  >
              
            
          
             <ItemDetailsTemplate>
           detail template: 
          <mobile:Label ID="Label1" Runat="server"><%# Eval("ID") 
%></mobile:Label> 
           <mobile:Label ID="Label2" Runat="server"><%# Eval("UserTitle") 
%></mobile:Label> 
              
            </ItemDetailsTemplate>
     
          </Choice>
          
          </DeviceSpecific>  
          
          
          <Field Title="ID" DataField="ID" />
          <Field Title="UserTitle" DataField="UserTitle" />
        </mobile:ObjectList>
========================

Also, I found a good web forum thread which has included some advanced 
setting and usage upon ObjectList  control, you can also have a look if you 
need some further customzation or event handling:

http://forums.asp.net/p/1146753/1862202.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

 

==================================================

Get notification to my posts through email? Please refer to 
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

 

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues 
where an initial response from the community or a Microsoft Support 
Engineer within 1 business day is acceptable. Please note that each follow 
up response may take approximately 2 business days as the support 
professional working with you may need further investigation to reach the 
most efficient resolution. The offering is not appropriate for situations 
that require urgent, real-time or phone-based interactions or complex 
project analysis and dump analysis issues. Issues of this nature are best 
handled working with a dedicated Microsoft Support Engineer by contacting 
Microsoft Customer Support Services (CSS) at 
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
 	

This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Mon, 20 Aug 2007 06:29:49 GMT   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us