locked
ObjectList and footertemplate RRS feed

  • Question

  • User1577742094 posted

    I created a web page for the purpose of learning about the ObjectList control.  The list items are not displaying after I add a Footer Template via the designer (they display fine if I don't use a footer...autogenerate is set to 'no').  Am I required to use an Item Template if I use a Footer Template?  Also, can anyone recommend a good book for building mobile web apps with VS 2005?  My code is below:
    Note:  ObjectList control displays paging information for service call paging and acknowledgement.

     

    1    <mobile:Form id="Form1" runat="server">
    2       <mobile:Label ID="Label1" Runat="server" Alignment="Center">Unacknowledged Notices</mobile:Label>
    3            <mobile:ObjectList ID="NoticeList" Runat="server" Alignment="Left"  
    4                CommandStyle-StyleReference="subcommand"
    5                OnItemCommand="Notice_OnItemCommand" LabelField="PageID" AutoGenerateFields="False"
    6                LabelStyle-StyleReference="title">           
    7                <Command Name="Acknowledge" Text="Acknowledge" />
    8                <DeviceSpecific>
    9                    <Choice Xmlns="http://schemas.microsoft.com/mobile/html32template">
    10                       <FooterTemplate>
    11                           <mobile:Label ID="Label4" Runat="server">My Footer</mobile:Label>
    12                       </FooterTemplate>
    13                   </Choice>
    14               </DeviceSpecific>
    15               <Field DataField="PageID" Title="PageID" />
    16               <Field DataField="SourceID" Title="SourceID" />
    17               <Field DataField="EscLevel" Title="EscLevel" />
    18               <Field DataField="NoticeDtTm" Title="NoticeDtTm" />
    19           </mobile:ObjectList>
    20        </mobile:Form>
    21   .
    22   .
    23   .
    24   Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
    25           If (Not IsPostBack) Then
    26               Dim array As New ArrayList
    27               ' test data
    28               array.Add(New Notice("00323110", "no source", "E2", "08/13/07", "test 1"))
    29               array.Add(New Notice("00323221", "no source", "E1", "08/14/07", "test 2"))
    30               array.Add(New Notice("00324001", "no source", "E2", "08/14/07", "test 3"))
    31   
    32               NoticeList.DataSource = array
    33               NoticeList.DataBind()   
    34               NoticeList.TableFields = "PageID;NoticeDtTm;SourceID"
    35           End If
    36   End Sub
    37   
    
     
    Thanks.
    Wednesday, August 15, 2007 11:58 AM

Answers

  • User1565039490 posted

    You are right. You are required to use ItemTemplate if you use FooterTemplate. So, add the following lines of code above the <FooterTemplate>:

     

    <ItemTemplate>
      
    <mobile:Label id="ID" runat="server" Text='<%# Ctype(Container, ObjectListItem)("PageID") %>'> </mobile:Label>
       <mobile:Label id="Label2" runat="server" Text='<%# Ctype(Container, ObjectListItem)("source") %>'> </mobile:Label>
       <mobile:Label id="Label3" runat="server" Text='<%# Ctype(Container, ObjectListItem)("code") %>'> </mobile:Label>
       <mobile:Label id="Label5" runat="server" Text='<%# Ctype(Container, ObjectListItem)("someStatus") %>'> </mobile:Label>
    </ItemTemplate>

    You can use the following link to get insight into mobile development:

    http://samples.gotdotnet.com/mobilequickstart/(S(x4dvanyyu3mb12rmwsilwue0))/Default.aspx

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 15, 2007 3:12 PM
  • User1565039490 posted

    Good approach. By the way you can also bind data to some mobile controls programmically:

    Imports Info

    Partial Class Mobile
        Inherits System.Web.UI.MobileControls.MobilePage

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If Not IsPostBack Then
       
            Dim array As New ArrayList
                ' test data
                array.Add(New Info("00323110", "no source", "E2", "08/13/07", "ServiceList1"))
                array.Add(
    New Info("00323221", "no source", "E1", "08/14/07", "ServiceList2"))
                array.Add(
    New Info("00324001", "no source", "E2", "08/14/07", "ServiceList3"))

                NoticeList.DataSource = array
                NoticeList.LabelField =
    "PageID"
       
            NoticeList.DataBind()
            End If
        End Sub

        Protected Sub NoticeList1_ItemCommand( _
           
    ByVal sender As Object, _
            ByVal e As System.Web.UI.MobileControls.ObjectListCommandEventArgs) Handles NoticeList.ItemCommand

            If e.CommandName = "Acknowledge" Then
               
    ' Show the Summary text

               
    Label2.Text = _
               
    String.Format("{0}, AKA: '{1}', initials: '{2}'", _
                    e.ListItem(
    "PageID"), e.ListItem("SourceID"), _
                    e.ListItem(
    "EscLevel"))
           
    ElseIf e.CommandName = "MoreInfo" Then
               
    ' Show the More Info text
                   
    Label2.Text = String.Format("{0}'s source ID was {1} and service list was {2}", _
                    e.ListItem(
    "NoticeDtTm"), e.ListItem("SourceID"), e.ListItem("ServiceList"))
           
    End If
            
    Me.ActiveForm = frmDetails
       
    End Sub

        Protected Sub Command1_Click(ByVal sender As Object, _
           
    ByVal e As EventArgs) Handles Command1.Click
           
    ' Show the first form

            Me.ActiveForm = frmMain
        End Sub

    End Class

     <mobile:Form id="frmMain" runat="server">
       
    <mobile:Label ID="Label1" Runat="server" Alignment="Center">Unacknowledged Notices</mobile:Label>
       
    <mobile:ObjectList ID="NoticeList" Runat="server" Alignment="Left" CommandStyle-StyleReference="subcommand" LabelStyle-StyleReference="title"  OnItemCommand="NoticeList1_ItemCommand">

            <Command Name="Acknowledge" Text="Acknowledge" />
            <Command Name="MoreInfo" Text="More Info" />

            <Field DataField="PageID" Title="PageID" />
            <Field DataField="SourceID" Title="SourceID" />
            <Field DataField="EscLevel" Title="EscLevel" />
            <Field DataField="NoticeDtTm" Title="NoticeDtTm" />
            <Field DataField="ServiceList" Title="ServiceList" />

        </mobile:ObjectList>

    </mobile:Form>

    <mobile:Form ID="frmDetails" Runat="server">
       
    <mobile:Label ID="Label2" runat="server" />
       
    <mobile:Command ID="Command1" Runat="server" OnClick="Command1_Click">Return</mobile:Command>
    </mobile:Form>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 17, 2007 8:05 AM

All replies

  • User1565039490 posted

    You are right. You are required to use ItemTemplate if you use FooterTemplate. So, add the following lines of code above the <FooterTemplate>:

     

    <ItemTemplate>
      
    <mobile:Label id="ID" runat="server" Text='<%# Ctype(Container, ObjectListItem)("PageID") %>'> </mobile:Label>
       <mobile:Label id="Label2" runat="server" Text='<%# Ctype(Container, ObjectListItem)("source") %>'> </mobile:Label>
       <mobile:Label id="Label3" runat="server" Text='<%# Ctype(Container, ObjectListItem)("code") %>'> </mobile:Label>
       <mobile:Label id="Label5" runat="server" Text='<%# Ctype(Container, ObjectListItem)("someStatus") %>'> </mobile:Label>
    </ItemTemplate>

    You can use the following link to get insight into mobile development:

    http://samples.gotdotnet.com/mobilequickstart/(S(x4dvanyyu3mb12rmwsilwue0))/Default.aspx

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 15, 2007 3:12 PM
  • User1577742094 posted

    Thank you very much for your response and the sample code.  My declarative data binding syntax was incorrect so the sample code really helped.  I have created an ItemTemplate and an ItemDetailsTemplate (see code below).  I'd like to take advantage of the built-in functionality of the ObjectList and switch from List View to Detail View (rather than creating a new form) when the user selects an item from the list, but I'm unsure how to do it.  I tried adding a link in my item template and setting the NoticeList.ViewMode.Property in my Notice_OnItemCommand, but I received the following error:  "System.Exception:  To set the ViewMode to Commands or Details, you must first select an item".  Can you provide me with any information regarding viewing the details for a selected item when using an ItemTemplate.  I did check the samples.gotdotnet.com site, but didn't find anything for this particular problem.  Thanks in advance for any assistance you may provide. 

    1       <mobile:Form id="Form1" runat="server">
    2            <mobile:Label ID="Label1" Runat="server" Alignment="Center">Unacknowledged Notices</mobile:Label>
    3            <mobile:ObjectList ID="NoticeList" Runat="server" Alignment="Left" CommandStyle-StyleReference="subcommand"
    4                OnItemCommand="Notice_OnItemCommand" LabelField="PageID" AutoGenerateFields="False" LabelStyle-StyleReference="title">          
    5                <Command Name="Acknowledge" Text="Acknowledge" />
    6             <DeviceSpecific>
    7                    <Choice Xmlns="http://schemas.microsoft.com/mobile/html32template">
    8                        <ItemTemplate>
    9                                <asp:LinkButton ID="lbnTask" CommandName="details" Runat="server">
    10                               <%# Ctype(Container, ObjectListItem)("PageID") %></asp:LinkButton>
    11                               <br></br>
    12                       </ItemTemplate>
    13                       <ItemDetailsTemplate>
    14                           <mobile:Label ID="Lbl" Runat="server" Text='PageID:' BreakAfter="False"></mobile:Label><mobile:Label id="ID" runat="server" Text='<%# Ctype(Container, ObjectListItem)("PageID") %>'></mobile:Label>
    15                           <mobile:Label ID="Lbl5" Runat="server" Text='SourceID:' BreakAfter="False"></mobile:Label><mobile:Label id="Label5" runat="server" Text='<%# Ctype(Container, ObjectListItem)("SourceID") %>'> </mobile:Label>
    16                           <mobile:Label ID="Lbl6" Runat="server" Text='EscLevel:' BreakAfter="False"></mobile:Label><mobile:Label id="Label6" runat="server" Text='<%# Ctype(Container, ObjectListItem)("EscLevel") %>'> </mobile:Label>
    17                           <mobile:Label ID="Lbl7" Runat="server" Text='NoticeDtTm:' BreakAfter="False"></mobile:Label><mobile:Label id="Label7" runat="server" Text='<%# Ctype(Container, ObjectListItem)("NoticeDtTm") %>'>
    18                           </mobile:Label><br>
    19                       <br></br>
    20                       </ItemDetailsTemplate>
    21                       <FooterTemplate>
    22                           <mobile:SelectionList ID="AckCallList" Runat="server" Rows="1" SelectType="CheckBox" Visible="False">
    23                               <Item Text="Acknowledge Call" Value="Y" Selected="True" />
    24                           </mobile:SelectionList>
    25                           <mobile:SelectionList ID="ContactedList" Runat="server" Rows="1" SelectType="CheckBox" Visible="False">
    26                               <Item Text="Customer Contacted" Value="Y" Selected="True" />
    27                           </mobile:SelectionList>
    28                           <mobile:SelectionList ID="ServiceList" Runat="server" Rows="1" SelectType="CheckBox" Visible="False">
    29                               <Item Text="Service Initiated" Value="Y" Selected="False" />
    30                           </mobile:SelectionList>
    31                       </FooterTemplate>
    32                   </Choice>
    33               </DeviceSpecific>
    34               <Field DataField="PageID" Title="PageID" />
    35               <Field DataField="SourceID" Title="SourceID" />
    36               <Field DataField="EscLevel" Title="EscLevel" />
    37               <Field DataField="NoticeDtTm" Title="NoticeDtTm" />
    38           </mobile:ObjectList>
    39        </mobile:Form>

     
    Thursday, August 16, 2007 2:24 PM
  • User1577742094 posted

    I was able to get this to work with the following code:

     

    1    If (e.CommandName = "details") Then
    2                NoticeList.SelectedIndex = e.ListItem.Index
    3                NoticeList.ViewMode = ObjectListViewMode.Details
    4    End If
    
     
    Thursday, August 16, 2007 4:36 PM
  • User1565039490 posted

    Good approach. By the way you can also bind data to some mobile controls programmically:

    Imports Info

    Partial Class Mobile
        Inherits System.Web.UI.MobileControls.MobilePage

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If Not IsPostBack Then
       
            Dim array As New ArrayList
                ' test data
                array.Add(New Info("00323110", "no source", "E2", "08/13/07", "ServiceList1"))
                array.Add(
    New Info("00323221", "no source", "E1", "08/14/07", "ServiceList2"))
                array.Add(
    New Info("00324001", "no source", "E2", "08/14/07", "ServiceList3"))

                NoticeList.DataSource = array
                NoticeList.LabelField =
    "PageID"
       
            NoticeList.DataBind()
            End If
        End Sub

        Protected Sub NoticeList1_ItemCommand( _
           
    ByVal sender As Object, _
            ByVal e As System.Web.UI.MobileControls.ObjectListCommandEventArgs) Handles NoticeList.ItemCommand

            If e.CommandName = "Acknowledge" Then
               
    ' Show the Summary text

               
    Label2.Text = _
               
    String.Format("{0}, AKA: '{1}', initials: '{2}'", _
                    e.ListItem(
    "PageID"), e.ListItem("SourceID"), _
                    e.ListItem(
    "EscLevel"))
           
    ElseIf e.CommandName = "MoreInfo" Then
               
    ' Show the More Info text
                   
    Label2.Text = String.Format("{0}'s source ID was {1} and service list was {2}", _
                    e.ListItem(
    "NoticeDtTm"), e.ListItem("SourceID"), e.ListItem("ServiceList"))
           
    End If
            
    Me.ActiveForm = frmDetails
       
    End Sub

        Protected Sub Command1_Click(ByVal sender As Object, _
           
    ByVal e As EventArgs) Handles Command1.Click
           
    ' Show the first form

            Me.ActiveForm = frmMain
        End Sub

    End Class

     <mobile:Form id="frmMain" runat="server">
       
    <mobile:Label ID="Label1" Runat="server" Alignment="Center">Unacknowledged Notices</mobile:Label>
       
    <mobile:ObjectList ID="NoticeList" Runat="server" Alignment="Left" CommandStyle-StyleReference="subcommand" LabelStyle-StyleReference="title"  OnItemCommand="NoticeList1_ItemCommand">

            <Command Name="Acknowledge" Text="Acknowledge" />
            <Command Name="MoreInfo" Text="More Info" />

            <Field DataField="PageID" Title="PageID" />
            <Field DataField="SourceID" Title="SourceID" />
            <Field DataField="EscLevel" Title="EscLevel" />
            <Field DataField="NoticeDtTm" Title="NoticeDtTm" />
            <Field DataField="ServiceList" Title="ServiceList" />

        </mobile:ObjectList>

    </mobile:Form>

    <mobile:Form ID="frmDetails" Runat="server">
       
    <mobile:Label ID="Label2" runat="server" />
       
    <mobile:Command ID="Command1" Runat="server" OnClick="Command1_Click">Return</mobile:Command>
    </mobile:Form>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 17, 2007 8:05 AM
  • User1577742094 posted

    Thanks so much for the additional information. [:)]

    Friday, August 17, 2007 8:47 AM