User Control Page /MobileModules/Announcements.ascx (C#)
1: <%@ Control language="c#" Inherits="ASPNetPortal.MobilePortalModuleControl" %>
2: <%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>
3: <%@ Register TagPrefix="portal" TagName="Title" Src="~/MobileModuleTitle.ascx" %>
4: <%@ Register TagPrefix="portal" Namespace="ASPNetPortal.MobileControls" Assembly="Portal" %>
5: <%@ Import Namespace="System.Data" %>
6: <%--
7:
8: The Announcements Mobile User Control renders announcement modules in the
9: portal for mobile devices.
10:
11: The control consists of two pieces: a summary panel that is rendered when
12: portal view shows a summarized view of all modules, and a multi-part panel
13: that renders the module details.
14:
15: --%>
16: <script runat="server">
17:
18: DataSet ds = null;
19: int currentIndex = 0;
20:
21: //*********************************************************************
22: //
23: // Page_Load Event Handler
24: //
25: // The Page_Load event handler on this User Control is used to
26: // obtain a DataSet of announcement information from the Announcements
27: // table, and then databind the results to the module contents. It uses
28: // the ASPNetPortal.AnnouncementsDB() data component
29: // to encapsulate all data functionality.
30: //
31: //*******************************************************
32:
33: void Page_Load(Object sender, EventArgs e) {
34:
35: // Obtain announcement information from Announcements table
36: ASPNetPortal.AnnouncementsDB announcements = new ASPNetPortal.AnnouncementsDB();
37: ds = announcements.GetAnnouncements(ModuleId);
38:
39: // DataBind the User Control
40: DataBind();
41: }
42:
43: //*********************************************************************
44: //
45: // SummaryView_OnItemCommand Event Handler
46: //
47: // The SummaryView_OnItemCommand event handler is called when the user
48: // clicks on a "More" link in the summary view. It calls the
49: // ShowAnnouncementDetails utility method to show details of the
50: // announcement.
51: //
52: //*********************************************************************
53:
54: void SummaryView_OnItemCommand(Object sender, RepeaterCommandEventArgs e) {
55: ShowAnnouncementDetails(e.Item.ItemIndex);
56: }
57:
58: //*********************************************************************
59: //
60: // AnnouncementsList_OnItemCommand Event Handler
61: //
62: // The AnnouncementsList_OnItemCommand event handler is called when the user
63: // clicks on an item in the list of announcements. It calls the
64: // ShowAnnouncementDetails utility method to show details of the
65: // announcement.
66: //
67: //*********************************************************************
68:
69: void AnnouncementsList_OnItemCommand(Object sender, ListCommandEventArgs e) {
70: ShowAnnouncementDetails(e.ListItem.Index);
71: }
72:
73: //*********************************************************************
74: //
75: // DetailsView_OnClick Event Handler
76: //
77: // The DetailsView_OnClick event handler is called when the user
78: // clicks in the details view to return to the summary view.
79: //
80: //*********************************************************************
81:
82: void DetailsView_OnClick(Object sender, EventArgs e) {
83:
84: // Make the parent tab show module summaries again.
85: Tab.SummaryView = true;
86: }
87:
88: //*********************************************************************
89: //
90: // ShowAnnouncementDetails Method
91: //
92: // The ShowAnnouncementDetails method sets the active pane of
93: // the module to the details view, and shows the details of the
94: // given item.
95: //
96: //*********************************************************************
97:
98: void ShowAnnouncementDetails(int itemIndex) {
99:
100: currentIndex = itemIndex;
101:
102: // Switch the visible pane of the multi-panel view to show
103: // announcement details
104: MainView.ActivePane = AnnouncementDetails;
105:
106: // Rebind the details panel
107: AnnouncementDetails.DataBind();
108:
109: // Make the parent tab switch to details mode, showing this module
110: Tab.ShowDetails(this);
111: }
112:
113: //*********************************************************************
114: //
115: // FormatChildField Method
116: //
117: // The FormatChildField method returns the selected field as a string,
118: // if the row is not empty. If empty, it returns String.Empty.
119: //
120: //*********************************************************************
121:
122: string FormatChildField (string fieldName) {
123:
124: if (ds.Tables[0].Rows.Count > 0)
125: return ds.Tables[0].Rows[currentIndex][fieldName].ToString();
126: else
127: return String.Empty;
128: }
129:
130: </script>
131: <mobile:Panel id="summary" runat="server">
132: <DeviceSpecific>
133: <Choice Filter="isJScript">
134: <ContentTemplate>
135: <portal:Title runat="server" />
136: <font face="Verdana" size="-2">
137: <asp:Repeater id="announcementList" DataSource="<%# ds %>" OnItemCommand="SummaryView_OnItemCommand" runat="server">
138: <ItemTemplate>
139: <asp:LinkButton runat="server">
140: <%# DataBinder.Eval(Container.DataItem, "Title") %>
141: </asp:LinkButton>
142: <br>
143: </ItemTemplate>
144: </asp:Repeater>
145: </font>
146: <br>
147: </ContentTemplate>
148: </Choice>
149: </DeviceSpecific>
150: </mobile:Panel>
151: <portal:MultiPanel id="MainView" Font-Name="Verdana" Font-Size="Small" runat="server">
152: <portal:ChildPanel id="AnnouncementsList" runat="server">
153: <portal:Title runat="server" />
154: <mobile:List runat="server" DataTextField="Title" DataSource="<%# ds %>" OnItemCommand="AnnouncementsList_OnItemCommand" />
155: </portal:ChildPanel>
156: <portal:ChildPanel id="AnnouncementDetails" runat="server">
157: <portal:Title runat="server" Text='<%# FormatChildField("Title") %>' />
158: <mobile:TextView runat="server" Text='<%# FormatChildField("Description") %>' />
159: <mobile:Link runat="server" NavigateUrl='<%# FormatChildField("MobileMoreLink") %>' Visible='<%# FormatChildField("MobileMoreLink") != String.Empty %>' Text="read more" />
160: <portal:LinkCommand runat="server" OnClick="DetailsView_OnClick" Text="back" />
161: </portal:ChildPanel>
162: </portal:MultiPanel>