zhengqi12345 2017-05-23 02:46 采纳率: 0%
浏览 772

asp.net重写GridView后无法获取到对应的id属性

求大神指点为什么重写之后,再页面引用这个重写的GridView进行调用,
后台却无法使用id.DataSource属性

  • 写回答

1条回答 默认 最新

  • zhengqi12345 2017-05-23 02:41
    关注

    重写的gridview代码
    /*----------------------------------------------------------------
    -----------------------------------------------------------------*/
    using System;
    using System.Text;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using System.Drawing;
    using System.Web.UI.Design;
    using System.Drawing.Design;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;

    namespace Fujifilm.ColorOrganizer.UI.Common.GridViewExtensions
    {
    ///
    /// GridViewExtension
    ///
    [ToolboxData("<{0}:GridViewExtensions runat=\"server\"></{0}:GridViewExtensions>")]
    [Description("GridViewExtensions")]
    public class GridViewExtensions : GridView, INamingContainer, IPostBackDataHandler, IPostBackEventHandler
    {
    ///
    ///
    ///
    public enum BUTTON_TYPE
    {
    Text = 0,
    Image = 1
    }

        /// <summary>
        /// ventTextChanged 
        /// </summary>
        private static readonly object EventTextChanged = new object();
        /// <summary>
        /// �y�[�W
        /// </summary>
        public event EventHandler ChangePageIndex;
    
        #region PageNowWidth
    
        [DefaultValue(typeof(Unit), "")]
        [Category("")]
        [Description("")]
        public Unit PageNowWidth
        {
            get
            {
                object o = ViewState["PageNowWidth"];
                if (o != null)
                {
                    return (Unit)o;
                }
                return Unit.Empty;
            }
            set
            {
                ViewState["PageNowWidth"] = value;
            }
        }
    
        [DefaultValue(typeof(Unit), "")]
        [Category("")]
        [Description("")]
        public Unit PageRowWidth
        {
            get
            {
                object o = ViewState["PageRowWidth"];
                if (o != null)
                {
                    return (Unit)o;
                }
                return Unit.Empty;
            }
            set
            {
                ViewState["PageRowWidth"] = value;
            }
        }
    
        [DefaultValue(typeof(FontUnit), "")]
        [Category("")]
        [Description("")]
        public FontUnit PageFontSize
        {
            get
            {
                object o = ViewState["PageFontSize"];
                if (o != null)
                {
                    return (FontUnit)o;
                }
                return FontUnit.Empty;
            }
            set
            {
                ViewState["PageFontSize"] = value;
            }
        }
    
        [DefaultValue(typeof(Color), "")]
        [Category("")]
        [TypeConverter(typeof(WebColorConverter))]
        [Description("")]
        public Color PageFontColor
        {
            get
            {
                object o = ViewState["PageFontColor"];
                if (o != null)
                {
                    return (Color)o;
                }
                return Color.Empty;
            }
            set
            {
                ViewState["PageFontColor"] = value;
            }
        }
    
        [DefaultValue(typeof(Color), "")]
        [Category("")]
        [TypeConverter(typeof(WebColorConverter))]
        [Description("")]
        public Color PageBackColor
        {
            get
            {
                object o = ViewState["PageBackColor"];
                if (o != null)
                {
                    return (Color)o;
                }
                return Color.Empty;
            }
            set
            {
                ViewState["PageBackColor"] = value;
            }
        }
    
        [Category("")]
        [DefaultValue(typeof(Color), "")]
        [TypeConverter(typeof(WebColorConverter))]
        [Description("")]
        public Color PageBorderColor
        {
            get
            {
                object o = ViewState["PageBorderColor"];
                if (o != null)
                {
                    return (Color)o;
                }
                return Color.Empty;
            }
            set
            {
                ViewState["PageBorderColor"] = value;
            }
        }
    
        [DefaultValue(typeof(Unit), "")]
        [Category("")]
        [Description("")]
        public Unit PageBorderWidth
        {
            get
            {
                object o = ViewState["PageBorderWidth"];
                if (o != null)
                {
                    return (Unit)o;
                }
                return Unit.Empty;
            }
            set
            {
                ViewState["PageBorderWidth"] = value;
            }
        }
    
        #endregion
    
        #region ��ҳ����ť��ʽ
    
        [DefaultValue(GridViewExtensions.BUTTON_TYPE.Text)]
        [Category("")]
        [Description("")]
        public BUTTON_TYPE PageButtonType
        {
            get
            {
                object o = ViewState["PageButtonType"];
                if (o != null)
                {
                    return (BUTTON_TYPE)o;
                }
                return BUTTON_TYPE.Text;
            }
            set
            {
                ViewState["PageButtonType"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Editor(typeof(ImageUrlEditor), typeof(UITypeEditor))]
        [Description("")]
        public string PageFirstImage
        {
            get
            {
                object o = ViewState["PageFirstImage"];
                if (o != null)
                {
                    return (string)o;
                }
                return string.Empty;
            }
            set
            {
                ViewState["PageFirstImage"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Editor(typeof(ImageUrlEditor), typeof(UITypeEditor))]
        [Description("")]
        public string PageBackImage
        {
            get
            {
                object o = ViewState["PageBackImage"];
                if (o != null)
                {
                    return (string)o;
                }
                return string.Empty;
            }
            set
            {
                ViewState["PageBackImage"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Editor(typeof(ImageUrlEditor), typeof(UITypeEditor))]
        [Description("")]
        public string PageNextImage
        {
            get
            {
                object o = ViewState["PageNextImage"];
                if (o != null)
                {
                    return (string)o;
                }
                return string.Empty;
            }
            set
            {
                ViewState["PageNextImage"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Editor(typeof(ImageUrlEditor), typeof(UITypeEditor))]
        [Description("")]
        public string PageLastImage
        {
            get
            {
                object o = ViewState["PageLastImage"];
                if (o != null)
                {
                    return (string)o;
                }
                return string.Empty;
            }
            set
            {
                ViewState["PageLastImage"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Description("")]
        public string PagerableCssClass
        {
            get
            {
                object o = ViewState["PagerableCssClass"];
                if (o != null)
                {
                    return (string)o;
                }
                return string.Empty;
            }
            set
            {
                ViewState["PagerableCssClass"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Description("")]
        public string PageNowFormat
        {
            get
            {
                object o = ViewState["PageNowFormat"];
                if (o != null)
                {
                    return (string)o;
                }
                return "";
            }
            set
            {
                ViewState["PageNowFormat"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Description("")]
        public string PageRowFormat
        {
            get
            {
                object o = ViewState["PageRowFormat"];
                if (o != null)
                {
                    return (string)o;
                }
                return "";
            }
            set
            {
                ViewState["PageRowFormat"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Description("")]
        public string PageFirstFormat
        {
            get
            {
                object o = ViewState["PageFirstFormat"];
                if (o != null)
                {
                    return (string)o;
                }
                return "��ҳ";
            }
            set
            {
                ViewState["PageFirstFormat"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Description("")]
        public string PageBackFormat
        {
            get
            {
                object o = ViewState["PageBackFormat"];
                if (o != null)
                {
                    return (string)o;
                }
                return "��һҳ";
            }
            set
            {
                ViewState["PageBackFormat"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Description("")]
        public string PageNextFormat
        {
            get
            {
                object o = ViewState["PageNextFormat"];
                if (o != null)
                {
                    return (string)o;
                }
                return "";
            }
            set
            {
                ViewState["PageNextFormat"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Description("")]
        public string PageLastFormat
        {
            get
            {
                object o = ViewState["PageLastFormat"];
                if (o != null)
                {
                    return (string)o;
                }
                return "";
            }
            set
            {
                ViewState["PageLastFormat"] = value;
            }
        }
    
        #endregion
    
        #region ��ת����ʽ
    
        [DefaultValue(typeof(Unit), "")]
        [Category("")]
        [Description("")]
        public Unit PageJumpWidth
        {
            get
            {
                object o = ViewState["PageJumpWidth"];
                if (o != null)
                {
                    return (Unit)o;
                }
                return Unit.Empty;
            }
            set
            {
                ViewState["PageJumpWidth"] = value;
            }
        }
    
        [DefaultValue(GridViewExtensions.BUTTON_TYPE.Text)]
        [Category("")]
        [Description("")]
        public BUTTON_TYPE JumpButtonType
        {
            get
            {
                object o = ViewState["JumpButtonType"];
                if (o != null)
                {
                    return (BUTTON_TYPE)o;
                }
                return BUTTON_TYPE.Text;
            }
            set
            {
                ViewState["JumpButtonType"] = value;
            }
        }
    
        [DefaultValue("")]
        [Category("")]
        [Editor(typeof(ImageUrlEditor), typeof(UITypeEditor))]
        [Description("")]
        public string JumpButtonImage
        {
            get
            {
                object o = ViewState["JumpButtonImage"];
                if (o != null)
                {
                    return (string)o;
                }
                return string.Empty;
            }
            set
            {
                ViewState["JumpButtonImage"] = value;
            }
        }
    
        [DefaultValue(typeof(Color), "")]
        [Category("")]
        [TypeConverter(typeof(WebColorConverter))]
        [Description("")]
        public Color JumpButtonBorderColor
        {
            get
            {
                object o = ViewState["JumpButtonBorderColor"];
                if (o != null)
                {
                    return (Color)o;
                }
                return Color.Empty;
            }
            set
            {
                ViewState["JumpButtonBorderColor"] = value;
            }
        }
    
        [DefaultValue(typeof(Unit), "")]
        [Category("")]
        [Description("")]
        public Unit JumpButtonBorderWidth
        {
            get
            {
                object o = ViewState["JumpButtonBorderWidth"];
                if (o != null)
                {
                    return (Unit)o;
                }
                return Unit.Empty;
            }
            set
            {
                ViewState["JumpButtonBorderWidth"] = value;
            }
        }
    
        [DefaultValue(typeof(Unit), "")]
        [Category("")]
        [Description("")]
        public Unit JumpButtonHeight
        {
            get
            {
                object o = ViewState["JumpButtonHeight"];
                if (o != null)
                {
                    return (Unit)o;
                }
                return Unit.Pixel(25);
            }
            set
            {
                ViewState["JumpButtonHeight"] = value;
            }
        }
    
        [DefaultValue(typeof(Unit), "")]
        [Category("")]
        [Description("")]
        public Unit JumpButtonWidth
        {
            get
            {
                object o = ViewState["JumpButtonWidth"];
                if (o != null)
                {
                    return (Unit)o;
                }
                return Unit.Pixel(25);
            }
            set
            {
                ViewState["JumpButtonWidth"] = value;
            }
        }
    
        [DefaultValue(typeof(Color), "")]
        [Category("")]
        [TypeConverter(typeof(WebColorConverter))]
        [Description("")]
        public Color JumpButtonBackColor
        {
            get
            {
                object o = ViewState["JumpButtonBackColor"];
                if (o != null)
                {
                    return (Color)o;
                }
                return Color.Empty;
            }
            set
            {
                ViewState["JumpButtonBackColor"] = value;
            }
        }
    
        [DefaultValue(typeof(Unit), "")]
        [Category("")]
        [Description("")]
        public Unit JumpTextBoxHeight
        {
            get
            {
                object o = ViewState["JumpTextBoxHeight"];
                if (o != null)
                {
                    return (Unit)o;
                }
                return Unit.Pixel(20);
            }
            set
            {
                ViewState["JumpTextBoxHeight"] = value;
            }
        }
    
        [DefaultValue(typeof(Unit), "")]
        [Category("")]
        [Description("")]
        public Unit JumpTextBoxWidth
        {
            get
            {
                object o = ViewState["JumpTextBoxWidth"];
                if (o != null)
                {
                    return (Unit)o;
                }
                return Unit.Pixel(20);
            }
            set
            {
                ViewState["JumpTextBoxWidth"] = value;
            }
        }
    
        [DefaultValue(typeof(Unit), "")]
        [Category("")]
        [Description("")]
        public Unit JumpTextBoxBorderWidth
        {
            get
            {
                object o = ViewState["JumpTextBoxBorderWidth"];
                if (o != null)
                {
                    return (Unit)o;
                }
                return Unit.Empty;
            }
            set
            {
                ViewState["JumpTextBoxBorderWidth"] = value;
            }
        }
    
        [DefaultValue(typeof(Color), "")]
        [Category("")]
        [TypeConverter(typeof(WebColorConverter))]
        [Description("")]
        public Color JumpTextBoxBorderColor
        {
            get
            {
                object o = ViewState["JumpTextBoxBorderColor"];
                if (o != null)
                {
                    return (Color)o;
                }
                return Color.Empty;
            }
            set
            {
                ViewState["JumpTextBoxBorderColor"] = value;
            }
        }
    
        [DefaultValue("")]
        [Browsable(false)]
        public string Text
        {
            get
            {
                object o = ViewState["Text"];
                if (o != null)
                {
                    return (string)o;
                }
                return string.Empty;
            }
            set
            {
                ViewState["Text"] = value;
            }
        }
    
        #endregion
    
        #region start
    
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(0)]
        [Browsable(false)]
        private int FirstNumericButton
        {
            get
            {
                object o = ViewState["FirstNumericButton"];
                if (o != null)
                {
                    return (int)o;
                }
                return 0;
            }
            set
            {
                ViewState["FirstNumericButton"] = value;
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(false)]
        [Category("")]
        [Description("")]
        public bool ShowNumericButton
        {
            get
            {
                object o = ViewState["ShowNumericButton"];
                if (o != null)
                {
                    return (bool)o;
                }
                return false;
            }
            set
            {
                ViewState["ShowNumericButton"] = value; ;
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(true)]
        [Category("")]
        [Description("")]
        public bool AllowPagerable
        {
            get
            {
                object o = ViewState["AllowPagerable"];
                if (o != null)
                {
                    return (bool)o;
                }
                return true;
            }
            set
            {
                ViewState["AllowPagerable"] = value;
            }
        }
    
        /// <summary>
        ///
        /// </summary>
        [DefaultValue(0)]
        [Category("")]
        [Description("")]
        public Int32 PageViewIndex
        {
            get
            {
                object o = ViewState["PageViewIndex"];
                if (o != null)
                {
                    return (Int32)o;
                }
                return (Int32)0;
            }
            set
            {
                ViewState["PageViewIndex"] = value;
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(10)]
        [Category("")]
        [Description("")]
        public Int32 PageViewSize
        {
            get
            {
                object o = ViewState["PageViewSize"];
                if (o != null)
                {
                    return (Int32)o;
                }
                return (Int32)10;
            }
            set
            {
                this.PageSize = value;
                ViewState["PageViewSize"] = value;
            }
        }
    
        /// <summary>
        ///
        /// </summary>
        [DefaultValue(1)]
        [Browsable(false)]
        public Int32 PageViewCount
        {
            get
            {
                object o = ViewState["PageViewCount"];
                if (o != null)
                {
                    return (Int32)o;
                }
                return (Int32)1;
            }
            set
            {
                ViewState["PageViewCount"] = value;
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        [Browsable(false)]
        public Int32 PageRowCount
        {
            get
            {
                object o = ViewState["PageRowCount"];
                if (o != null)
                {
                    return (Int32)o;
                }
                return (Int32)10;
            }
            set
            {
                ViewState["PageRowCount"] = value;
            }
        }
    
        #endregion
    
        #region �ű��ļ�
    
        /// <summary>
        /// 
        /// </summary>
        private string BuildScript()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("function CheckNum(evt) {");
            sb.AppendLine("if((evt.keyCode >= 96 && evt.keyCode <= 105) ||");
            sb.AppendLine("(evt.keyCode >= 48 && evt.keyCode <= 57)  ||");
            sb.AppendLine("evt.keyCode == 8  || evt.keyCode == 37 ||");
            sb.AppendLine("evt.keyCode == 38 || evt.keyCode == 39 ||");
            sb.AppendLine("evt.keyCode == 40 || evt.keyCode == 13) ");
            sb.AppendLine("{");
            sb.AppendLine("if(evt.keyCode == 13)");
            sb.AppendLine("{");
            sb.AppendFormat("{0};", Page.ClientScript.GetPostBackEventReference(this, "jump"));
            sb.AppendLine("}");
            sb.AppendLine("return true;");
            sb.AppendLine("}");
            sb.AppendLine("else{ return false; } }");
            return sb.ToString();
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private string CreateJavascript()
        {
            string divid = string.Format("{0}_table_Container", this.ClientID);
            StringBuilder str = new StringBuilder();
    
            //str.Append("<script type=\"text/javascript\">");
            str.AppendFormat("IniCellWidth('{0}');", divid);
            //str.Append("</script>");
    
            return str.ToString();
        }
    
        #endregion
    
        #region RenderNumeric
    
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private void RenderNumericButton(HtmlTextWriter writer)
        {
            int i = 10;
    
            //
            int endindex = this.FirstNumericButton + i;
            //
            int endpage = this.PageViewCount % 10;
    
            if (endpage != 0 && (this.PageViewIndex > (this.PageViewCount - endpage - 1) &&
                this.PageViewIndex < this.PageViewCount))
            { //
                endindex = this.PageViewCount;
            }
    
            for (int j = this.FirstNumericButton; j < endindex; j++)
            {
                if (j == this.PageViewIndex)
                { //
                    CreateNumericButton(writer, j, false);
                }
                else
                {
                    CreateNumericButton(writer, j, true);
                }
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="text"></param>
        private void CreateNumericButton(HtmlTextWriter writer, int text, bool show)
        {
            writer.Write("&nbsp;");
    
            string strtext = string.Format("{0}", text + 1);
    
            if (show == true)
            { //
                writer.AddStyleAttribute(HtmlTextWriterStyle.TextDecoration, "none");
                writer.AddAttribute(HtmlTextWriterAttribute.Href, Page.ClientScript.GetPostBackClientHyperlink(this, "pager$" + text.ToString()));
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                writer.Write(strtext);
                writer.RenderEndTag();
            }
            else
            { //
                writer.Write(strtext);
            }
            writer.Write("&nbsp;");
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private string RenderPageNow()
        {
            string templateCell = string.Format(PageNowFormat, PageViewIndex + 1, PageViewCount);
            return templateCell;
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private string RenderPageRow()
        {
            string templateCell = string.Format(PageRowFormat, PageViewSize, PageRowCount);
            return templateCell;
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private string RenderFirst()
        {
            string templateCell = string.Empty;
    
            if (PageButtonType == BUTTON_TYPE.Text)
            {
                if (PageViewIndex <= 0)
                {
                    templateCell = PageFirstFormat;
                }
                else
                {
                    templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\">{1}</a>",
                        Page.ClientScript.GetPostBackClientHyperlink(this, "pager$0"), PageFirstFormat);
                }
            }
            else
            {
                if (PageViewIndex <= 0)
                {
                    templateCell = string.Format("<img border=\"0\" src=\"{0}\" />", ConverImageUrl(PageFirstImage));
                }
                else
                {
                    templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\"><img border=\"0\" src=\"{1}\" /></a>",
                        Page.ClientScript.GetPostBackClientHyperlink(this, "pager$0"), ConverImageUrl(PageFirstImage));
                }
            }
            return templateCell;
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private string RenderLast()
        {
            string templateCell = string.Empty;
    
            if (PageButtonType == BUTTON_TYPE.Text)
            {
                if (PageViewIndex >= PageViewCount - 1)
                {
                    templateCell = PageLastFormat;
                }
                else
                {
                    templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\">{1}</a>",
                        Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewCount - 1)), PageLastFormat);
                }
            }
            else
            {
                if (PageViewIndex >= PageViewCount - 1)
                {
                    templateCell = string.Format("<img border=\"0\" src=\"{0}\" />", ConverImageUrl(PageLastImage));
                }
                else
                {
                    templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\"><img border=\"0\" src=\"{1}\" /></a>",
                        Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewCount - 1)), ConverImageUrl(PageLastImage));
                }
            }
    
            return templateCell;
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private string RenderBack()
        {
            string templateCell = string.Empty;
    
            if (PageButtonType == BUTTON_TYPE.Text)
            {
                if (PageViewIndex <= 0)
                { //
                    templateCell = PageBackFormat;
                }
                else
                {
                    templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\">{1}</a>",
                        Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewIndex - 1)), PageBackFormat);
                }
            }
            else
            {
                if (PageViewIndex <= 0)
                { //
                    templateCell = string.Format("<img border=\"0\" src=\"{0}\" />", ConverImageUrl(PageBackImage));
                }
                else
                {
                    templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\"><img border=\"0\" src=\"{1}\" /></a>",
                        Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewIndex - 1)), ConverImageUrl(PageBackImage));
                }
            }
    
            return templateCell;
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private string RenderNext()
        {
            string templateCell = string.Empty;
    
            if (PageButtonType == BUTTON_TYPE.Text)
            {
                if (PageViewIndex >= PageViewCount - 1)
                { //
                    templateCell = PageNextFormat;
                }
                else
                {
                    templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\">{1}</a>",
                        Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewIndex + 1)), PageNextFormat);
                }
            }
            else
            {
                if (PageViewIndex >= PageViewCount - 1)
                { //
                    templateCell = string.Format("<img border=\"0\" src=\"{0}\" />", ConverImageUrl(PageNextImage));
                }
                else
                {
                    templateCell = string.Format("<a href=\"{0}\" style=\"text-decoration:none\"><img border=\"0\" src=\"{1}\" /></a>",
                        Page.ClientScript.GetPostBackClientHyperlink(this, string.Format("pager${0}", PageViewIndex + 1)), ConverImageUrl(PageNextImage));
                }
            }
    
            return templateCell;
        }
    
        #endregion
    
        #region ͼƬ·��ת��
    
        private string ResolvePhysicalLocation(string path)
        {
            ISite site1 = this.GetSite();
            if (site1 == null)
            {
                return path;
            }
            IWebApplication application1 = (IWebApplication)site1.GetService(typeof(IWebApplication));
            IProjectItem item1 = application1.GetProjectItemFromUrl(path);
            if (item1 != null)
            {
                return item1.PhysicalPath;
            }
            return path.Replace("~/", application1.RootProjectItem.PhysicalPath);
        }
    
        private ISite GetSite()
        {
            if (base.Site != null)
            {
                return base.Site;
            }
            for (Control control1 = this.Parent; control1 != null; control1 = control1.Parent)
            {
                if (control1.Site != null)
                {
                    return control1.Site;
                }
            }
            return null;
        }
    
        private void RenderImage(HtmlTextWriter writer, string imageurl)
        {
            if (this.Page != null)
            {
                string text1 = this.Page.ResolveUrl(imageurl);
                if (base.DesignMode)
                {
                    string text2 = this.ResolvePhysicalLocation(text1);
                    text1 = text2;
                }
                writer.AddAttribute(HtmlTextWriterAttribute.Src, text1);
            }
            writer.RenderBeginTag(HtmlTextWriterTag.Img);
            writer.RenderEndTag();
        }
    
        private string ConverImageUrl(string url)
        {
            string text1 = this.Page.ResolveUrl(url);
            return this.ResolvePhysicalLocation(text1);
        }
    
        #endregion
    
        #region �ط����ݺ��¼�
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="postDataKey"></param>
        /// <param name="postCollection"></param>
        /// <returns></returns>
        public bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            string postedValue = postCollection[postDataKey];
            string presentValue = Text;
    
            if (presentValue == null || postedValue != presentValue)
            {
                Text = postedValue;
                return true;
            }
    
            return false;
    
        }
    
        /// <summary>
        /// 
        /// </summary>
        public void RaisePostDataChangedEvent()
        {
            OnTextChanged(EventArgs.Empty);
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="eventArgs"></param>
        private void OnTextChanged(EventArgs eventArgs)
        {
            EventHandler textChangedHandler = (EventHandler)Events[EventTextChanged];
    
            if (textChangedHandler != null)
            {
                textChangedHandler(this, eventArgs);
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler TextChanged
        {
            add
            {
                Events.AddHandler(EventTextChanged, value);
            }
            remove
            {
                Events.RemoveHandler(EventTextChanged, value);
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="eventArgument"></param>
        protected override void RaisePostBackEvent(string eventArgument)
        {
            base.RaisePostBackEvent(eventArgument);
    
            if (this.AllowPagerable == true)
            {
                string[] str = eventArgument.Split('$');
    
                if (str[0] == "jump")
                { //
                    Int32 pi;
                    try
                    {
                        string index = (string)ViewState["Text"];
                        pi = Int32.Parse(index);
                        pi -= 1;
                    }
                    catch
                    {
                        pi = PageViewIndex;
                    }
    
                    if (pi >= 0 && pi <= PageViewCount - 1)
                    {
                        PageViewIndex = pi;
                    }
                    else
                    {
                        PageViewIndex = PageViewCount - 1;
                    }
    
                    OnChangePageIndex(new EventArgs());
                }
                else if (str[0] == "pager")
                { //
                    PageViewIndex = Int32.Parse(str[1]);
    
                    OnChangePageIndex(new EventArgs());
                }
    
                if (this.ShowNumericButton == true)
                {
                    if (this.PageViewIndex >= (this.FirstNumericButton + 10))
                    { //
                        if (this.PageViewIndex == (this.PageViewCount - 1))
                        {  //
                            if ((this.PageViewCount % 10) == 0)
                            { //
                                this.FirstNumericButton = this.PageViewIndex - 10 + 1;
                            }
                            else
                            {
                                this.FirstNumericButton = this.PageViewIndex - (this.PageViewCount % 10) + 1;
                            }
                        }
                        else
                        {
                            this.FirstNumericButton = this.PageViewIndex;
                        }
                    }
                    else if (this.PageViewIndex < this.FirstNumericButton)
                    { //
                        if (this.PageViewIndex == 0)
                        {  //
                            this.FirstNumericButton = 0;
                        }
                        else
                        {
                            this.FirstNumericButton = this.PageViewIndex - 10 + 1;
                        }
                    }
    
                    OnChangePageIndex(new EventArgs());
                }
    
    
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        private void OnChangePageIndex(EventArgs e)
        {
            ChangePageIndex(this, e);
        }
    
        #endregion
    
        #region �����ҳ��
    
        public override void RenderControl(HtmlTextWriter writer)
        {
            if (BottomPagerRow != null)
            {
                BottomPagerRow.Cells.Clear();
            }
    
            base.RenderControl(writer);
        }
    
        private string ColorFormat(Color color)
        {
            string str = color.Name;
    
            if (str.ToUpper().StartsWith("FF"))
            {
                str = "#" + str.Remove(0, 2);
            }
    
            return str;
        }
    
        #endregion
    
        #region ��������
    
        public override Unit Width
        {
            get
            {
                if (base.Width == Unit.Empty && AllowChangeCellWidth == false)
                {
                    return Unit.Percentage(100);
                }
                return base.Width;
            }
            set
            {
                base.Width = value;
            }
        }
    
        [Browsable(false)]
        public override PagerSettings PagerSettings
        {
            get
            {
                return base.PagerSettings;
            }
        }
    
        [Browsable(false)]
        public override bool AllowPaging
        {
            get
            {
                return true;
            }
            set
            {
                base.AllowPaging = value;
            }
        }
    
        [Browsable(false)]
        public override int PageCount
        {
            get
            {
                return base.PageCount;
            }
        }
    
        [Browsable(false)]
        public override int PageIndex
        {
            get
            {
                return base.PageIndex;
            }
            set
            {
                base.PageIndex = value;
            }
        }
    
        [Browsable(false)]
        public override int PageSize
        {
            get
            {
                return base.PageSize;
            }
            set
            {
                base.PageSize = value;
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(false)]
        [Description("�Ƿ������ı�ÿ�еĿ���")]
        public bool AllowChangeCellWidth
        {
            get
            {
                object o = ViewState["AllowChangeCellWidth"];
                if (o != null)
                {
                    return (bool)o;
                }
                return false;
            }
            set
            {
                ViewState["AllowChangeCellWidth"] = value;
            }
        }
    
        #endregion
    
        #region RenderBeginTag
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            string divid = string.Format("{0}_table_Container", this.ClientID);
            string tbodyid = string.Format("{0}_GridBody_Cells", this.ClientID);
    
            if (AllowChangeCellWidth == true)
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, "tableContainer");
                writer.AddAttribute(HtmlTextWriterAttribute.Id, divid);
                writer.AddAttribute("onmousedown", string.Format("TableOnMouseDown('{0}');", divid));
                writer.AddAttribute("onmouseup", string.Format("TableOnMouseUp('{0}');", tbodyid));
                writer.AddAttribute("onmousemove", "TableOnMouseMove();");
                writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
            }
    
            base.RenderBeginTag(writer);
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        public override void RenderEndTag(HtmlTextWriter writer)
        {
            base.RenderEndTag(writer);
    
            if (AllowChangeCellWidth == true)
            {
                writer.RenderEndTag();
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(HtmlTextWriter writer)
        {
            if (AllowChangeCellWidth == true)
            {
                int i = 0;
    
                if (HeaderRow != null)
                {
                    foreach (TableCell cell in HeaderRow.Cells)
                    {
                        string str = cell.Text;
                        cell.ID = i.ToString();
                        cell.Text = string.Format("<div class=\"gridCell_standard\" columnIndex=\"{0}\">{1}</div>", i, str);
                        i++;
                    }
                }
            }
    
            base.Render(writer);
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        protected override void RenderContents(HtmlTextWriter writer)
        {
            string tbodyid = string.Format("{0}_GridBody_Cells", this.ClientID);
    
            if (AllowChangeCellWidth == true)
            {
                //
                string str = string.Empty;
    
                this.RenderBeginTag(writer);
    
                if (this.HeaderRow != null)
                {
                    this.HeaderRow.RenderControl(writer);
                }
    
                writer.AddAttribute(HtmlTextWriterAttribute.Id, tbodyid);
                writer.RenderBeginTag(HtmlTextWriterTag.Tbody);
    
                if (Rows != null)
                {
                    foreach (GridViewRow row in this.Rows)
                    {
                        foreach (TableCell cell in row.Cells)
                        {
                            if (cell.HasControls())
                            {
                                cell.Controls.AddAt(0, new LiteralControl("<div class=\"gridCell_standard\">"));
                                cell.Controls.Add(new LiteralControl("</div>"));
                            }
                            else
                            {
                                str = cell.Text;
                                cell.Text = string.Format("<div class=\"gridCell_standard\">{0}</div>", str);
                            }
                        }
                        row.RenderControl(writer);
                    }
                }
    
                writer.RenderEndTag();
    
                if (this.FooterRow != null)
                {
                    this.FooterRow.RenderControl(writer);
                }
    
                this.RenderEndTag(writer);
    
                //writer.Write(this.CreateJavascript());
            }
            else
            {
                //base.RenderBeginTag(writer);
                base.RenderContents(writer);
                //base.RenderEndTag(writer);
    
            }
        }
    
        #endregion
    
        #region Page_PreRenderComplete
    
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_PreRenderComplete(object sender, EventArgs e)
        {
            string str = string.Format("{0}_gridviewini", this.ClientID);
    
            Page.ClientScript.RegisterClientScriptResource(this.GetType(), "~.Scripts.gridview.js");
    
            //
            if (!Page.ClientScript.IsStartupScriptRegistered(str) && AllowChangeCellWidth == true)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), str, this.CreateJavascript(), true);
            }
    
            //
            if (!Page.ClientScript.IsClientScriptBlockRegistered("CheckNum"))
            {
                string js = BuildScript();
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CheckNum", js, true);
            }
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            this.Page.PreRenderComplete += new EventHandler(this.Page_PreRenderComplete);
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        private void RegisterCssFile(string path)
        {
            HtmlLink link1 = new HtmlLink();
            link1.Attributes["type"] = "text/css";
            link1.Attributes["rel"] = "stylesheet";
            link1.Attributes["href"] = path;
            this.Page.Header.Controls.Add(link1);
        }
    
        #endregion
    
    }
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?