自定义了一个分页控件,为什么在
protected override void RenderContents(HtmlTextWriter output) 方法中无法引用 sqlConnection,头部也无法引用System.Data命名空间!怎么弄啊!

解决方案 »

  1.   

    下面是控件代码!刚学!请多指教using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    namespace mypage
    {
        [DefaultProperty("Text")]
        [ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
        public class WebCustomControl1 : WebControl
        {
            [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("")]
            [Localizable(true)]
            public string Text
            {
                get
                {
                    String s = (String)ViewState["Text"];
                    return ((s == null) ? String.Empty : s);
                }            set
                {
                    ViewState["Text"] = value;
                }
            }
            [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("")]
            [Localizable(true)]
            public int PageSize
            {
                get
                {
                    try
                    {
                        Int32 s = (Int32)ViewState["PageSize"];
                        return ((s == null) ? 5 : s);
                    }
                    catch
                    {
                        return 5;
                    }
                    
                }
                set
                {
                    ViewState["PageSize"] = value;
                }
            }        [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("")]
            [Localizable(true)]
            public string DataPath
            {
                get
                {
                    string s = (String)ViewState["DataPath"];
                    return ((s == null) ? ("~/App_Data/data.mdb") : s);
                }
                set
                {
                    ViewState["DataPath"] = value;
                }
            }
            [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("")]
            [Localizable(true)]
            public string Table
            {
                get
                {
                    string s = (String)ViewState["Table"];
                    return ((s == null) ? ("news") : s);
                }
                set
                {
                    ViewState["Table"] = value;
                }        }
            [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("")]
            [Localizable(true)]
            public string sqlCommand
            {
                get
                {
                    string s = (String)ViewState["sqlCommand"];
                    return ((s == null) ? ("select * ") : s);
                }
                set
                {
                    ViewState["sqlCommand"] = value;
                }
            }
            [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("")]
            [Localizable(true)]
            public string indexPage
            {
                get
                {
                    string s = (String)ViewState["indexPage"];
                    return ((s == null) ? ("none") : s);
                }
                set
                {
                    ViewState["indexPage"] = value;
                }
            }        [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("")]
            [Localizable(true)]
            public string pageName
            {
                get
                {
                    string s = (String)ViewState["pageName"];
                    return ((s == null) ? ("none") : s);
                }
                set
                {
                    ViewState["pageName"] = value;
                }
           
            }
            protected override void RenderContents(HtmlTextWriter output)
            {
               
                output.Write();
            }
        }
    }
      

  2.   

    在项目的结构图中的"引用"点右键,添加,在.net中选择System.Web即可
    然后再WebCustomControl1 这个类中添加using System.web就可以了!