Dave Burke : Freelance .NET Web Developer specializing in Online Communities

.Text Series Collection Code: Series Administration Page

I based the Series Administration page  (shown here) on the Categories Administration page.  I shouldn't say "page", since both the Categories and Series administrative forms are loaded in a .Text AdvancedPanel panel control and pages are generated from Paul Wilson's Master Pages design approach (according to ScottW's inline documentation.)   I can't tell you much more than that, but I can tell you that because of this underlying design and page rendering, I had a heckuva time binding to a dropdown list located in a Datagrid EditItemTemplate OnItemDataBound in the DataGrid's OnEditItem method.  This is pretty standard stuff, normally.  So instead of pulling out the rest of the little hair I have left I went with an Edit LinkButton in the datagrid to display the edit form in a separate AdvancedPanel rather than keep things within the DataGrid as in the Categories Admin control design.

First I needed a "Edit Series" sidebar link added to EditPosts.aspx.cs.   Constants were added to the sealed Constants class in Utilities.cs.

EditPosts.aspx.cs

HyperLink lnkEditSeries = Utilities.CreateHyperLink("Edit Series",
 String.Format("{0}?{1}={2}", Constants.URL_EDITSERIES, Keys.QRYSTR_CATEGORYID,
 (int)PageContainer.CategoryType));
PageContainer.AddToActions(lnkEditSeries);

Constants.cs

internal const string RES_SUCCESSCATEGORYUPDATE = "Categories and Series updated successfully.";
internal const string RES_FAILURECATEGORYUPDATE = "Category or Series Update failed.";
internal const string URL_EDITSERIES = "EditSeries.aspx";

Something of note was the change required to the blog_GetCategories stored procedure.  (As I stated before, a Series object is a Category with a different CategoryType value.)  The query to return the extended LinkCategory data object (now with ParentCatID and ParentTitle properties) was changed to the following.


 

The only differing factors of the Edit Series page from Edit Categories was populating the Edit form to include the Parent Categories, then updating the Series item or adding a new Series item.  First populating the form from the EDIT LinkButton.

protected void lbEdit_OnCommand(object source, CommandEventArgs e)
{
 int catID = int.Parse(e.CommandArgument.ToString());
 LinkCategory existingCategory = Links.GetLinkCategory(catID,false);
 LinkCategoryCollection selectionList = Links.GetCategories(CategoryType.PostCollection, true); 
 BindParentCats(ddParentCats, selectionList, existingCategory.ParentCategoryID);  // See below
 txbTitle.Text = existingCategory.Title;
 txbDescription.Text = existingCategory.Description;
 ckbEditIsActive.Checked = existingCategory.IsActive;
 BindList();
 this.Messages.Clear();
 ToggleAddNew(false);
 lkbUpdate.CommandArgument = catID.ToString();
}
  

private void BindParentCats(DropDownList _ddParentCats, LinkCategoryCollection _lcc, int parentcatID)
{
 if(_lcc != null && _lcc.Count != 0)
 {
  _ddParentCats.DataSource = _lcc;
  _ddParentCats.DataValueField = "CategoryID";
  _ddParentCats.DataTextField = "Title";
  _ddParentCats.DataBind();
  if (parentcatID != 0)
  {
   _ddParentCats.Items.FindByValue(parentcatID.ToString()).Selected = true;
  }
  else
  {
   _ddParentCats.Items.Insert(0,"");
  }
 }
 else
 {
  this.Messages.ShowError("You need to add a category before you can add series! Click \"Edit Categories\"");
 }
}


Updating or adding the series is identical to adding or editing a category, except for the new data layer methods.

private void PersistCategory(LinkCategory category)
{
 try
 {
  if (category.CategoryID > 0)
  {
   Links.UpdateLinkSeries(category);
   this.Messages.ShowMessage(String.Format("Series \"{0}\" was updated.", category.Title));
  }
  else
  {
   category.CategoryID = Links.CreateLinkSeries(category);
   this.Messages.ShowMessage(String.Format("Series \"{0}\" was added.", category.Title));
  }     
 }
 catch(Exception ex)
 {
  this.Messages.ShowError(String.Format(Constants.RES_EXCEPTION, "TODO...", ex.Message));
 }
}


  

Comments (0) | Post RSS RSS comment feed

Posted on 10/14/2004 8:40:00 AM by Dave Burke
Categories:
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke