Пример #1
0
 protected virtual void RenderVerbControl(HtmlTextWriter writer, WebControl control)
 {
     control.ApplyStyle(base.Zone.TitleBarVerbStyle);
     control.Page = base.WebPartManager.Page;
     control.RenderControl(writer);
 }
 void RenderButton(HtmlTextWriter writer)
 {
     IList<AttributeInfo> attributeInfoByCategoryId = new List<AttributeInfo>();
     attributeInfoByCategoryId = ProductBrowser.GetAttributeInfoByCategoryId(this.CategoryId);
     if (attributeInfoByCategoryId.Count > 0)
     {
         for (int i = 0; (i < this.MaxNum) && (i < attributeInfoByCategoryId.Count); i++)
         {
             WebControl control = new WebControl(HtmlTextWriterTag.Label);
             control.Controls.Add(new LiteralControl("<li>"));
             control.RenderControl(writer);
             WebControl control2 = new WebControl(HtmlTextWriterTag.Label);
             control2.Controls.Add(new LiteralControl("<span>" + attributeInfoByCategoryId[i].AttributeName + ":</span>"));
             control2.Attributes.Add("class", this.NameCss);
             control2.RenderControl(writer);
             WebControl control3 = new WebControl(HtmlTextWriterTag.A);
             control3.Controls.Add(new LiteralControl("全部"));
             if (!this.LinkSelf)
             {
                 control3.Attributes.Add("target", "_blank");
             }
             string str = "";
             if (!string.IsNullOrEmpty(this.ValueStr))
             {
                 string[] strArray = this.ValueStr.Split(new char[] { '-' });
                 if (strArray.Length >= 1)
                 {
                     for (int j = 0; j < strArray.Length; j++)
                     {
                         string[] strArray2 = strArray[j].Split(new char[] { '_' });
                         if ((strArray2.Length > 0) && (strArray2[0].IndexOf(attributeInfoByCategoryId[i].AttributeId.ToString()) != -1))
                         {
                             strArray2[1] = "0";
                             strArray[j] = strArray2[0] + "_" + strArray2[1];
                         }
                         if (string.IsNullOrEmpty(str))
                         {
                             str = str + strArray[j];
                         }
                         else
                         {
                             str = str + "-" + strArray[j];
                         }
                     }
                     if (str.IndexOf(attributeInfoByCategoryId[i].AttributeId.ToString()) == -1)
                     {
                         object obj2 = str;
                         str = string.Concat(new object[] { obj2, "-", attributeInfoByCategoryId[i].AttributeId, "_0" });
                     }
                 }
             }
             else
             {
                 str = attributeInfoByCategoryId[i].AttributeId + "_0";
             }
             if (string.IsNullOrEmpty(this.Page.Request.QueryString["valueStr"]))
             {
                 control3.Attributes.Add("class", this.AllCss);
             }
             else
             {
                 string str2 = this.Page.Request.QueryString["valueStr"];
                 if (str2 == str)
                 {
                     control3.Attributes.Add("class", this.AllCss);
                 }
             }
             control3.Attributes.Add("href", this.CreateUrl(str));
             control3.RenderControl(writer);
             foreach (AttributeValueInfo info in attributeInfoByCategoryId[i].AttributeValues)
             {
                 WebControl control4 = new WebControl(HtmlTextWriterTag.A);
                 control4.Controls.Add(new LiteralControl(info.ValueStr));
                 string str3 = "";
                 if (!string.IsNullOrEmpty(this.ValueStr))
                 {
                     string[] strArray3 = this.ValueStr.Split(new char[] { '-' });
                     if (strArray3.Length >= 1)
                     {
                         for (int k = 0; k < strArray3.Length; k++)
                         {
                             string[] strArray4 = strArray3[k].Split(new char[] { '_' });
                             if ((strArray4.Length > 0) && (strArray4[0].IndexOf(attributeInfoByCategoryId[i].AttributeId.ToString()) != -1))
                             {
                                 strArray4[1] = info.ValueId.ToString();
                                 strArray3[k] = strArray4[0] + "_" + strArray4[1];
                             }
                             if (string.IsNullOrEmpty(str3))
                             {
                                 str3 = str3 + strArray3[k];
                             }
                             else
                             {
                                 str3 = str3 + "-" + strArray3[k];
                             }
                         }
                         if (str3.IndexOf(attributeInfoByCategoryId[i].AttributeId.ToString()) == -1)
                         {
                             object obj3 = str3;
                             str3 = string.Concat(new object[] { obj3, "-", info.AttributeId, "_", info.ValueId });
                         }
                     }
                 }
                 else
                 {
                     str3 = info.AttributeId + "_" + info.ValueId;
                 }
                 bool flag = false;
                 if (!string.IsNullOrEmpty(this.Page.Request.QueryString["valueStr"]))
                 {
                     IList<AttributeValueInfo> list2 = new List<AttributeValueInfo>();
                     string str4 = Globals.UrlDecode(this.Page.Request.QueryString["valueStr"]);
                     string[] strArray5 = str4.Split(new char[] { '-' });
                     if (!string.IsNullOrEmpty(str4))
                     {
                         for (int m = 0; m < strArray5.Length; m++)
                         {
                             string[] strArray6 = strArray5[m].Split(new char[] { '_' });
                             if (((strArray6.Length > 0) && !string.IsNullOrEmpty(strArray6[1])) && (strArray6[1] != "0"))
                             {
                                 AttributeValueInfo item = new AttributeValueInfo();
                                 item.AttributeId = Convert.ToInt32(strArray6[0]);
                                 item.ValueId = Convert.ToInt32(strArray6[1]);
                                 if (info.ValueId == Convert.ToInt32(strArray6[1]))
                                 {
                                     control4.Attributes.Add("class", this.SelectCss);
                                     flag = true;
                                 }
                                 list2.Add(item);
                             }
                         }
                     }
                 }
                 if (!flag)
                 {
                     control4.Attributes.Add("href", this.CreateUrl(str3));
                 }
                 if (!this.LinkSelf)
                 {
                     control4.Attributes.Add("target", "_blank");
                 }
                 control4.RenderControl(writer);
             }
             WebControl control5 = new WebControl(HtmlTextWriterTag.Label);
             control5.Controls.Add(new LiteralControl("</li>"));
             control5.RenderControl(writer);
         }
     }
 }
Пример #3
0
 void RenderButton(HtmlTextWriter writer)
 {
     DataTable brandsByCategoryId = ProductBrowser.GetBrandsByCategoryId(this.CategoryId);
     if ((brandsByCategoryId != null) && (brandsByCategoryId.Rows.Count > 0))
     {
         WebControl control = new WebControl(HtmlTextWriterTag.Label);
         control.Controls.Add(new LiteralControl("<span>品牌:</span>"));
         control.RenderControl(writer);
         WebControl control2 = new WebControl(HtmlTextWriterTag.A);
         control2.Controls.Add(new LiteralControl("全部"));
         control2.Attributes.Add("href", this.urlFormatForALL);
         if (this.Context.Request.RawUrl.IndexOf("brand") < 0)
         {
             control2.Attributes.Add("class", this.AllCss);
         }
         control2.RenderControl(writer);
         foreach (DataRow row in brandsByCategoryId.Rows)
         {
             WebControl control3 = new WebControl(HtmlTextWriterTag.A);
             control3.Controls.Add(new LiteralControl(row["BrandName"].ToString()));
             if (this.SelectedBrand == int.Parse(row["BrandId"].ToString()))
             {
                 control3.Attributes.Add("class", this.SelectCss);
             }
             else
             {
                 control3.Attributes.Add("href", this.urlFormat + row["BrandId"].ToString());
             }
             control3.RenderControl(writer);
         }
     }
 }
Пример #4
0
 public static string RenderControl(WebControl control)
 {
     StringBuilder builder = new StringBuilder();
     StringWriter strWriter = new StringWriter(builder);
     HtmlTextWriter writer = new HtmlTextWriter(strWriter);
     control.RenderControl(writer);
     return builder.ToString();
 }
Пример #5
0
        ///<summary>
        ///导出到Excel
        ///</summary>
        ///<param name="ctrl">包含数据的控件</param>
        ///<param name="fileName">文件名</param>
        public static void ExportToExcel(WebControl ctrl, string fileName)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentType = "application/ms-excel";
            HttpContext.Current.Response.Charset = "UTF-8";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            //HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + fileName + ".xls");
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + ".xls");//这样的话,可以设置文件名为中文,且文件名不会乱码。其实就是将汉字转换成UTF8
            HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());

            StringWriter sw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
            ctrl.RenderControl(htw);
            HttpContext.Current.Response.Write(sw.ToString());
            HttpContext.Current.Response.End();
        }
Пример #6
0
 public static String getHTML(WebControl aControl)
 {
     StringWriter sr = new StringWriter();
       HtmlTextWriter writer = new HtmlTextWriter(sr);
       aControl.RenderControl(writer);
       writer.Dispose();
       return sr.ToString();
 }
Пример #7
0
 /// <summary>
 /// Renders The Given Control Into The String Output
 /// </summary>
 /// <param name="control">The WebControl To Be Converted</param>
 /// <returns>The Rendered Result Of The Given Control</returns>
 /// 
 private static string GetControl(WebControl control)
 {
     StringWriter stringWriter = new StringWriter();
     HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter);
     control.RenderControl(textWriter);
     textWriter.Flush();
     return textWriter.ToString();
 }