예제 #1
0
        private Item GetThisItemFromRight(Sitecore.Data.ID theItemID)
        {
            Item itm    = null;
            Item retVal = null;

            try
            {
                Database RightDB = Sitecore.Configuration.Factory.GetDatabase(strRightDB);
                if (RightDB != null)
                {
                    itm = RightDB.GetItem(theItemID);
                }
                if (itm != null)
                {
                    Sitecore.Data.Fields.TextField tf = null;
                    if (itm.TemplateName.ToString().ToLower() == "product")
                    {
                        tf = itm.Fields["_NDC"];
                    }
                    else if (itm.TemplateName.ToString().ToLower() == "productgroup")
                    {
                        tf = itm.Fields["Product Group Name"];
                    }

                    if ((tf != null) && (!String.IsNullOrWhiteSpace(tf.Value)))
                    {
                        retVal = itm;
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(retVal);
        }
예제 #2
0
        protected void rptCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                DataRowView      dr    = (DataRowView)e.Item.DataItem;
                Sitecore.Data.ID itmID = (Sitecore.Data.ID.Parse(dr["ProductCategoryItemID"].ToString()));
                if (itmID != Sitecore.Data.ID.Null)
                {
                    Sitecore.Data.Items.Item itm = webDB.GetItem(itmID);
                    if (itm != null)
                    {
                        Sitecore.Data.Fields.TextField catField = itm.Fields["Category"];
                        if ((catField != null) && (!String.IsNullOrWhiteSpace(catField.Value.ToString())))
                        {
                            String             category = catField.Value.ToString();
                            HtmlGenericControl lblName  = (HtmlGenericControl)e.Item.FindControl("lblCategory");
                            if (lblName != null)
                            {
                                lblName.InnerHtml = itm.Fields["Category"].Value.ToString();
                            }
                            HtmlAnchor anchr = (HtmlAnchor)e.Item.FindControl("CatAnch");
                            if (anchr != null)
                            {
                                anchr.Attributes.Add("href", String.Format("#{0}", category.ToLower().Replace(" ", "")));
                            }
                        }
                    }
                }
                DataView dv = dt.DefaultView;
                dv.RowFilter = String.Format("ProductCategoryItemID = '{0}'", itmID.ToString());

                String[]  ColumnsToFilter = { "ProductCategoryItemID", "ProductGroupItemID", "ItemID" };
                DataTable distinctGroups  = dv.ToTable(true, ColumnsToFilter);

                Repeater Groups = (Repeater)e.Item.FindControl("rptGroups");
                if (Groups != null)
                {
                    DataTable dtNew = distinctGroups;
                    distinctGroups.Columns.Add("AttrWarnings");
                    foreach (DataRow drNew in dtNew.Rows)
                    {
                        ID ndcItemID = Sitecore.Data.ID.Parse(drNew["ItemID"]);
                        if (ndcItemID != Sitecore.Data.ID.Null)
                        {
                            Item NDC = webDB.GetItem(ndcItemID);
                            if (NDC != null)
                            {
                                drNew["AttrWarnings"] += NDC.Fields["_xAttrWarnings"].Value.ToString();
                            }
                        }
                    }
                    Groups.DataSource = dtNew;
                    Groups.DataBind();
                }
            }
        }