// ********************************************************************* // OnPreRender // /// <summary> /// This event handler binds the template to the datalist - this action /// is only carried out if the user DID NOT specify an ItemTemplate. /// In such a case, the default databinding is used. /// </summary> /// // ********************************************************************/ protected override void OnPreRender(EventArgs e) { ForumGroupCollection forumGroups; // Get all forum groups (cached call) if (showAllForumGroups) { forumGroups = ForumGroups.GetAllForumGroups(true, false); } else { forumGroups = ForumGroups.GetAllForumGroups(false, true); } // Have we asked for a particular forum group? if (ForumGroupID > 0) { ForumGroupCollection newForumGroups = new ForumGroupCollection(); // Try to find the requested forum group foreach (ForumGroup f in forumGroups) { if (f.ForumGroupID == ForumGroupID) { newForumGroups.Add(f); } } forumGroups = newForumGroups; } // Databind if we have values if (forumGroups.Count > 0) { DataSource = forumGroups; DataBind(); } else // No forums { Label label; // Set some properties on the label label = new Label(); label.CssClass = "normalTextSmallBold"; label.Text = "Sorry, no forums are available."; // Clear the controls collection and add our label Controls.Clear(); Controls.Add(label); } }
private void RenderGroupsMenu() { ForumGroupCollection groups = ForumGroups.GetAllForumGroups(false, true); string groupMenu = "<div class='popupMenu' style='position: absolute; display: none;' id='" + this.UniqueID + ":groupMenu'>"; groupMenu += "<div class='popupTitle'>Forum Groups</div>"; for (int i = 0; i < groups.Count; i++) { groupMenu += "<div class='popupItem'> <a href='" + UrlShowForumGroup + ((ForumGroup)groups[i]).ForumGroupID + "'>" + ((ForumGroup)groups[i]).Name + "</a> </div>"; } groupMenu += "</div>"; Page.RegisterClientScriptBlock(this.UniqueID + ":groupMenu", groupMenu); }
/******************************************************************* * // PopulateListBox * // * /// <summary> * /// Used to populate the list box that lists the available forum groups * /// </summary> * // ********************************************************************/ public void PopulateListBox(int selectedForumGroupById) { ForumGroupCollection forums = ForumGroups.GetAllForumGroups(true, false); forumGroupList.DataTextField = "Name"; forumGroupList.DataValueField = "ForumGroupId"; forumGroupList.DataSource = forums; forumGroupList.Rows = forums.Count; forumGroupList.DataBind(); forumGroupList.AutoPostBack = true; forumGroupList.SelectedIndexChanged += new System.EventHandler(ForumGroupList_SelectionChange); if (selectedForumGroupById > 0) { forumGroupList.Items.FindByValue(selectedForumGroupById.ToString()).Selected = true; } else { forumGroupList.Items[0].Selected = true; } }
/// <summary> /// Populates the user control containing the form with the initial values for /// creating a new forum. /// </summary> /// <param name="control">An instance of the user control that contains the expected server controls.</param> private void PopulateCreateEditForum(Control control) { DropDownList dropdownlist; Button button; Label label; // Set the title label = (Label)control.FindControl("Title"); if (Mode == CreateEditForumMode.CreateForum) { label.Text = "Create a new forum"; } else { label.Text = "Edit an existing forum"; } // Fill the Forum Group Drop Down dropdownlist = (DropDownList)control.FindControl("ForumGroups"); dropdownlist.DataTextField = "Name"; dropdownlist.DataValueField = "ForumGroupId"; dropdownlist.DataSource = ForumGroups.GetAllForumGroups(true, false); dropdownlist.DataBind(); // Wire up the button click button = (Button)control.FindControl("CreateUpdate"); button.Click += new System.EventHandler(CreateUpdateForum_Click); // Initialize role based security UpdateRoleControls(control); if (Mode == CreateEditForumMode.CreateForum) { button.Text = "Create New Forum"; } else { button.Text = "Update Forum"; } }