• 自定义控件开发示例二


    本实例开发的是一个由2个ListBox和8个ImageButton组成的列表组件
    通过中间ImageButton可以控件列表项在两个列表中的位置
    到全右移 个右移 个左移 全左移
    通过右边ImageButton可以控件列表项在列表中的位置
    到第一位 上一位 下一位 到最后位
    示例图如下

    因为时间关系 现只将示例源代码写出
    示例代码

      1using System;
      2using System.Web.UI;
      3using System.Web.UI.WebControls;
      4using System.ComponentModel;
      5using System.Text;
      6
      7namespace JX_CC_LC
      8{
      9    /// <summary>
     10    /// LC_T02 的摘要描述。
     11    /// 清单类型控件项类型2
     12    /// 完成日期:2005-12-22
     13    /// 编码人员:Free
     14    /// </summary>

     15    //    [DefaultProperty("Text"), 
     16    //        ToolboxData("<{0}:LC_T02 runat=server></{0}:LC_T02>")]
     17    public class LC_T02 : WebControl, System.Web.UI.INamingContainer
     18    {
     19        //声明所要用到的 ListBox ,ImageButton
     20        private System.Web.UI.WebControls.ListBox ListBleft_LcT02;
     21        private System.Web.UI.WebControls.ListBox ListBright_LcT02;
     22
     23        private System.Web.UI.WebControls.ImageButton ibt_AllToR;
     24        private System.Web.UI.WebControls.ImageButton ibt_OneToR;
     25        private System.Web.UI.WebControls.ImageButton ibt_OneToL;
     26        private System.Web.UI.WebControls.ImageButton ibt_AllToL;
     27
     28        private System.Web.UI.WebControls.ImageButton ibt_First;
     29        private System.Web.UI.WebControls.ImageButton ibt_Pre;
     30        private System.Web.UI.WebControls.ImageButton ibt_Next;
     31        private System.Web.UI.WebControls.ImageButton ibt_Last;
     32
     33        private int wid = 150, hei = 200;
     34
     35        protected override void CreateChildControls()
     36        {
     37            this.Controls.Clear();
     38            //this.ClearChildViewState();
     39            //整体的大TABLE 
     40            this.Controls.Add(new LiteralControl("<table><tr><td><table><tr><td rowspan=5>"));
     41            //左半部分
     42            this.ListBleft_LcT02 = new ListBox();
     43            this.ListBleft_LcT02.Width = wid;
     44            this.ListBleft_LcT02.Height = hei;
     45            this.ListBleft_LcT02.ID = this.ID + "_leftListB";
     46            //this.ListBleft_LcT02.AutoPostBack=true;
     47            this.ListBleft_LcT02.MergeStyle(this.ControlStyle);
     48            this.Controls.Add(this.ListBleft_LcT02);
     49
     50            this.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
     51            this.ibt_AllToR = new ImageButton();
     52            this.ibt_AllToR.ImageUrl = "img/alltoright.JPG";
     53            this.ibt_AllToR.Attributes.Add("onclick"this.ID + "_allToR_click();return false;");
     54            this.Controls.Add(this.ibt_AllToR);
     55            this.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
     56            this.ibt_OneToR = new ImageButton();
     57            this.ibt_OneToR.ImageUrl = "img/onetoright.JPG";
     58            this.ibt_OneToR.Attributes.Add("onclick"this.ID + "_oneToR_click();return false;");
     59            this.Controls.Add(this.ibt_OneToR);
     60            this.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
     61            this.ibt_OneToL = new ImageButton();
     62            this.ibt_OneToL.ImageUrl = "img/onetoleft.JPG";
     63            this.ibt_OneToL.Attributes.Add("onclick"this.ID + "_oneToL_click();return false;");
     64            this.Controls.Add(this.ibt_OneToL);
     65            this.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
     66            this.ibt_AllToL = new ImageButton();
     67            this.ibt_AllToL.ImageUrl = "img/alltoleft.JPG";
     68            this.ibt_AllToL.Attributes.Add("onclick"this.ID + "_allToL_click();return false;");
     69            this.Controls.Add(this.ibt_AllToL);
     70            this.Controls.Add(new LiteralControl("</td></tr></table></td><td><table><tr><td rowspan=5>"));
     71            //右半部分
     72            this.ListBright_LcT02 = new ListBox();
     73            this.ListBright_LcT02.Width = wid;
     74            this.ListBright_LcT02.Height = hei;
     75            this.ListBright_LcT02.ID = this.ID + "_rightListB";
     76            //this.ListBright_LcT02.AutoPostBack=true;
     77            this.ListBright_LcT02.MergeStyle(this.ControlStyle);
     78            this.Controls.Add(this.ListBright_LcT02);
     79
     80            this.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
     81            this.ibt_First = new ImageButton();
     82            this.ibt_First.ImageUrl = "img/first.JPG";
     83            this.ibt_First.Attributes.Add("onclick"this.ID + "_first_click();return false;");
     84            this.Controls.Add(this.ibt_First);
     85            this.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
     86            this.ibt_Pre = new ImageButton();
     87            this.ibt_Pre.ImageUrl = "img/pre.JPG";
     88            this.ibt_Pre.Attributes.Add("onclick"this.ID + "_pre_click();return false;");
     89            this.Controls.Add(this.ibt_Pre);
     90            this.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
     91            this.ibt_Next = new ImageButton();
     92            this.ibt_Next.ImageUrl = "img/next.JPG";
     93            this.ibt_Next.Attributes.Add("onclick"this.ID + "_next_click();return false;");
     94            this.Controls.Add(this.ibt_Next);
     95            this.Controls.Add(new LiteralControl("</td></tr><tr><td>"));
     96            this.ibt_Last = new ImageButton();
     97            this.ibt_Last.ImageUrl = "img/last.JPG";
     98            this.ibt_Last.Attributes.Add("onclick"this.ID + "_last_click();return false;");
     99            this.Controls.Add(this.ibt_Last);
    100            this.Controls.Add(new LiteralControl("</td></tr></table></td>"));
    101            this.Controls.Add(new LiteralControl("</tr></table>"));
    102
    103            base.CreateChildControls();
    104
    105            //JS 部分
    106            //all to right
    107
    108            System.Text.StringBuilder strbuild = new StringBuilder();
    109            strbuild.Append("<script language='javascript'>");
    110
    111            strbuild.Append(" function " + this.ID + "_allToR_click(){");
    112            strbuild.Append(" var i=document.all." + this.ID + "_" + this.ID + "_leftListB.options.length;");
    113            strbuild.Append(" var i=document.all." + this.ID + "_" + this.ID + "_leftListB.options.length;");
    114            strbuild.Append(" var j=document.all." + this.ID + "_" + this.ID + "_rightListB.options.length;");
    115            strbuild.Append(" if(i>0){");
    116            strbuild.Append(" var tempvalue=document.all." + this.ID + "_" + this.ID + "_leftListB.options[0].value;");
    117            strbuild.Append(" var temptext=document.all." + this.ID + "_" + this.ID + "_leftListB.options[0].text;");
    118            strbuild.Append(" var temp=new Array([tempvalue,temptext]);");
    119            strbuild.Append(" for(ii=1;ii<i;ii++){");
    120            strbuild.Append(" var iv=document.all." + this.ID + "_" + this.ID + "_leftListB.options[ii].value;");
    121            strbuild.Append(" var it=document.all." + this.ID + "_" + this.ID + "_leftListB.options[ii].text;");
    122            strbuild.Append(" temp.push([iv,it]);");
    123            strbuild.Append(" }");
    124            strbuild.Append(" for(jj=0;jj<j;jj++){");
    125            strbuild.Append(" var jv=document.all." + this.ID + "_" + this.ID + "_rightListB.options[jj].value;");
    126            strbuild.Append(" var jt=document.all." + this.ID + "_" + this.ID + "_rightListB.options[jj].text;");
    127            strbuild.Append(" temp.push([jv,jt]);");
    128            strbuild.Append(" }");
    129            strbuild.Append(" temp.sort();");
    130            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options.length=0;");
    131            strbuild.Append(" for(ss=0;ss<i+j;ss++){");
    132            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[ss]=new Option(temp[ss][1],temp[ss][0]);");
    133            strbuild.Append(" }");
    134            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_leftListB.options.length=0;");
    135            strbuild.Append("} }</script>");
    136
    137            //one to right
    138
    139            strbuild.Append("<script language='javascript'>");
    140            strbuild.Append(" function " + this.ID + "_oneToR_click(){");
    141            strbuild.Append(" var i=document.all." + this.ID + "_" + this.ID + "_leftListB.selectedIndex;");
    142            strbuild.Append(" var j=document.all." + this.ID + "_" + this.ID + "_rightListB.options.length;");
    143            strbuild.Append(" if(i>=0){");
    144            strbuild.Append(" var tempvalue=document.all." + this.ID + "_" + this.ID + "_leftListB.options[i].value;");
    145            strbuild.Append(" var temptext=document.all." + this.ID + "_" + this.ID + "_leftListB.options[i].text;");
    146            strbuild.Append(" var temp=new Array([tempvalue,temptext]);");
    147            strbuild.Append(" for(jj=0;jj<j;jj++){");
    148            strbuild.Append(" var jv=document.all." + this.ID + "_" + this.ID + "_rightListB.options[jj].value;");
    149            strbuild.Append(" var jt=document.all." + this.ID + "_" + this.ID + "_rightListB.options[jj].text;");
    150            strbuild.Append(" temp.push([jv,jt]);");
    151            strbuild.Append(" }");
    152            strbuild.Append(" temp.sort();");
    153            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options.length=0;");
    154            strbuild.Append(" for(ss=0;ss<j+1;ss++){");
    155            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[ss]=new Option(temp[ss][1],temp[ss][0]);");
    156            strbuild.Append(" }");
    157            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_leftListB.remove(i);");
    158            strbuild.Append("} }</script>");
    159
    160            //one to left
    161
    162            strbuild.Append("<script language='javascript'>");
    163            strbuild.Append(" function " + this.ID + "_oneToL_click(){");
    164            strbuild.Append(" var i=document.all." + this.ID + "_" + this.ID + "_rightListB.selectedIndex;");
    165            strbuild.Append(" var j=document.all." + this.ID + "_" + this.ID + "_leftListB.options.length;");
    166            strbuild.Append(" if(i>=0){");
    167            strbuild.Append(" var tempvalue=document.all." + this.ID + "_" + this.ID + "_rightListB.options[i].value;");
    168            strbuild.Append(" var temptext=document.all." + this.ID + "_" + this.ID + "_rightListB.options[i].text;");
    169            strbuild.Append(" var temp=new Array([tempvalue,temptext]);");
    170            strbuild.Append(" for(jj=0;jj<j;jj++){");
    171            strbuild.Append(" var jv=document.all." + this.ID + "_" + this.ID + "_leftListB.options[jj].value;");
    172            strbuild.Append(" var jt=document.all." + this.ID + "_" + this.ID + "_leftListB.options[jj].text;");
    173            strbuild.Append(" temp.push([jv,jt]);");
    174            strbuild.Append(" }");
    175            strbuild.Append(" temp.sort();");
    176            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_leftListB.options.length=0;");
    177            strbuild.Append(" for(ss=0;ss<j+1;ss++){");
    178            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_leftListB.options[ss]=new Option(temp[ss][1],temp[ss][0]);");
    179            strbuild.Append(" }");
    180            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.remove(i);");
    181            strbuild.Append("} }</script>");
    182
    183            //all to left
    184
    185            strbuild.Append("<script language='javascript'>");
    186            strbuild.Append(" function " + this.ID + "_allToL_click(){");
    187            strbuild.Append(" var i=document.all." + this.ID + "_" + this.ID + "_leftListB.options.length;");
    188            strbuild.Append(" var j=document.all." + this.ID + "_" + this.ID + "_rightListB.options.length;");
    189            strbuild.Append(" if(j>0){");
    190            strbuild.Append(" var tempvalue=document.all." + this.ID + "_" + this.ID + "_rightListB.options[0].value;");
    191            strbuild.Append(" var temptext=document.all." + this.ID + "_" + this.ID + "_rightListB.options[0].text;");
    192            strbuild.Append(" var temp=new Array([tempvalue,temptext]);");
    193            strbuild.Append(" for(jj=1;jj<j;jj++){");
    194            strbuild.Append(" var jv=document.all." + this.ID + "_" + this.ID + "_rightListB.options[jj].value;");
    195            strbuild.Append(" var jt=document.all." + this.ID + "_" + this.ID + "_rightListB.options[jj].text;");
    196            strbuild.Append(" temp.push([jv,jt]);");
    197            strbuild.Append(" }");
    198            strbuild.Append(" for(ii=0;ii<i;ii++){");
    199            strbuild.Append(" var iv=document.all." + this.ID + "_" + this.ID + "_leftListB.options[ii].value;");
    200            strbuild.Append(" var it=document.all." + this.ID + "_" + this.ID + "_leftListB.options[ii].text;");
    201            strbuild.Append(" temp.push([iv,it]);");
    202            strbuild.Append(" }");
    203            strbuild.Append(" temp.sort();");
    204            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_leftListB.options.length=0;");
    205            strbuild.Append(" for(ss=0;ss<i+j;ss++){");
    206            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_leftListB.options[ss]=new Option(temp[ss][1],temp[ss][0]);");
    207            strbuild.Append(" }");
    208            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options.length=0;");
    209            strbuild.Append("} }</script>");
    210
    211            //first
    212
    213            strbuild.Append("<script language='javascript'>");
    214            strbuild.Append(" function " + this.ID + "_first_click(){");
    215            strbuild.Append(" var i=document.all." + this.ID + "_" + this.ID + "_rightListB.options.length;");
    216            strbuild.Append(" var j=document.all." + this.ID + "_" + this.ID + "_rightListB.selectedIndex;");
    217            strbuild.Append(" if(i>1&&j>0){");
    218            strbuild.Append(" var tempValue=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].value;");
    219            strbuild.Append(" var tempText=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].text;");
    220            strbuild.Append(" for(var h=j;h>0;h--){");
    221            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[h].value=document.all." + this.ID + "_" + this.ID + "_rightListB.options[h-1].value;");
    222            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[h].text=document.all." + this.ID + "_" + this.ID + "_rightListB.options[h-1].text;");
    223            strbuild.Append(" }");
    224            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[0].value=tempValue;");
    225            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[0].text=tempText;");
    226            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.selectedIndex=0;");
    227            strbuild.Append("} }</script>");
    228
    229            //pre
    230            strbuild.Append("<script language='javascript'>");
    231            strbuild.Append(" function " + this.ID + "_pre_click(){");
    232            strbuild.Append(" var i=document.all." + this.ID + "_" + this.ID + "_rightListB.options.length;");
    233            strbuild.Append(" var j=document.all." + this.ID + "_" + this.ID + "_rightListB.selectedIndex;");
    234            strbuild.Append(" if(i>1&&j>0){");
    235            strbuild.Append(" var tempValue=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].value;");
    236            strbuild.Append(" var tempText=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].text;");
    237            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].value=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j-1].value;");
    238            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].text=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j-1].text;");
    239            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[j-1].value=tempValue;");
    240            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[j-1].text=tempText;");
    241            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.selectedIndex=j-1;");
    242            strbuild.Append("} }</script>");
    243
    244            //next
    245
    246            strbuild.Append("<script language='javascript'>");
    247            strbuild.Append(" function " + this.ID + "_next_click(){");
    248            strbuild.Append(" var i=document.all." + this.ID + "_" + this.ID + "_rightListB.options.length;");
    249            strbuild.Append(" var j=document.all." + this.ID + "_" + this.ID + "_rightListB.selectedIndex;");
    250            strbuild.Append(" if(i>1&&j<i-1){");
    251            strbuild.Append(" var tempValue=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].value;");
    252            strbuild.Append(" var tempText=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].text;");
    253            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].value=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j+1].value;");
    254            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].text=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j+1].text;");
    255            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[j+1].value=tempValue;");
    256            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[j+1].text=tempText;");
    257            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.selectedIndex=j+1;");
    258            strbuild.Append("} }</script>");
    259
    260            //last
    261
    262            strbuild.Append("<script language='javascript'>");
    263            strbuild.Append(" function " + this.ID + "_last_click(){");
    264            strbuild.Append(" var i=document.all." + this.ID + "_" + this.ID + "_rightListB.options.length;");
    265            strbuild.Append(" var j=document.all." + this.ID + "_" + this.ID + "_rightListB.selectedIndex;");
    266            strbuild.Append(" if(i>1&&j<i-1){");
    267            strbuild.Append(" var tempValue=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].value;");
    268            strbuild.Append(" var tempText=document.all." + this.ID + "_" + this.ID + "_rightListB.options[j].text;");
    269            strbuild.Append(" for(var h=j;h<i-1;h++){");
    270            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[h].value=document.all." + this.ID + "_" + this.ID + "_rightListB.options[h+1].value;");
    271            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[h].text=document.all." + this.ID + "_" + this.ID + "_rightListB.options[h+1].text;");
    272            strbuild.Append("}");
    273            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[i-1].value=tempValue;");
    274            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.options[i-1].text=tempText;");
    275            strbuild.Append(" document.all." + this.ID + "_" + this.ID + "_rightListB.selectedIndex=i-1;");
    276            strbuild.Append("} }</script>");
    277            this.Controls.Add(new LiteralControl(strbuild.ToString()));
    278        }

    279
    280        protected override void Render(HtmlTextWriter writer)
    281        {
    282            this.EnsureChildControls();
    283            base.Render(writer);
    284        }

    285
    286
    287        //控制图像显示
    288        [Bindable(false),
    289        Category("imagebuttonsrc"),
    290        DefaultValue("")]
    291        //全右移
    292        public string alltoright_src
    293        {
    294            get
    295            {
    296                this.EnsureChildControls();
    297                return ((ImageButton)Controls[3]).ImageUrl;
    298
    299            }

    300            set
    301            {
    302                this.EnsureChildControls();
    303                ((ImageButton)Controls[3]).ImageUrl = value;
    304            }

    305        }

    306        //个右移
    307        public string onetoright_src
    308        {
    309            get
    310            {
    311                this.EnsureChildControls();
    312                return ((ImageButton)Controls[5]).ImageUrl;
    313            }

    314            set
    315            {
    316                this.EnsureChildControls();
    317                ((ImageButton)Controls[5]).ImageUrl = value;
    318            }

    319        }

    320        //个左移
    321        public string onetoleft_src
    322        {
    323            get
    324            {
    325                this.EnsureChildControls();
    326                return ((ImageButton)Controls[7]).ImageUrl;
    327            }

    328            set
    329            {
    330                this.EnsureChildControls();
    331                ((ImageButton)Controls[7]).ImageUrl = value;
    332            }

    333        }

    334        //全左移
    335        public string alltoleft_src
    336        {
    337            get
    338            {
    339                this.EnsureChildControls();
    340                return ((ImageButton)Controls[9]).ImageUrl;
    341            }

    342            set
    343            {
    344                this.EnsureChildControls();
    345                ((ImageButton)Controls[9]).ImageUrl = value;
    346            }

    347        }

    348        //最先
    349        public string first_src
    350        {
    351            get
    352            {
    353                this.EnsureChildControls();
    354                return ((ImageButton)Controls[13]).ImageUrl;
    355            }

    356            set
    357            {
    358                this.EnsureChildControls();
    359                ((ImageButton)Controls[13]).ImageUrl = value;
    360            }

    361        }

    362        //前一
    363        public string pre_src
    364        {
    365            get
    366            {
    367                this.EnsureChildControls();
    368                return ((ImageButton)Controls[15]).ImageUrl;
    369            }

    370            set
    371            {
    372                this.EnsureChildControls();
    373                ((ImageButton)Controls[15]).ImageUrl = value;
    374            }

    375        }

    376        //后一
    377        public string next_src
    378        {
    379            get
    380            {
    381                this.EnsureChildControls();
    382                return ((ImageButton)Controls[17]).ImageUrl;
    383            }

    384            set
    385            {
    386                this.EnsureChildControls();
    387                ((ImageButton)Controls[17]).ImageUrl = value;
    388            }

    389        }

    390        //最后
    391        public string last_src
    392        {
    393            get
    394            {
    395                this.EnsureChildControls();
    396                return ((ImageButton)Controls[19]).ImageUrl;
    397            }

    398            set
    399            {
    400                this.EnsureChildControls();
    401                ((ImageButton)Controls[19]).ImageUrl = value;
    402            }

    403        }

    404
    405        //公开左右LISTBOX的相关属性和方法
    406        //iDataSource
    407        public object iDataSourceL
    408        {
    409            get
    410            {
    411                this.EnsureChildControls();
    412                return ((ListBox)Controls[1]).DataSource;
    413            }

    414            set
    415            {
    416                this.EnsureChildControls();
    417                ((ListBox)Controls[1]).DataSource = value;
    418            }

    419        }

    420        public object iDataSourceR
    421        {
    422            get
    423            {
    424                this.EnsureChildControls();
    425                return ((ListBox)Controls[11]).DataSource;
    426            }

    427            set
    428            {
    429                this.EnsureChildControls();
    430                ((ListBox)Controls[11]).DataSource = value;
    431            }

    432        }

    433        //
    434        public string iDataTextFieldL
    435        {
    436            get
    437            {
    438                this.EnsureChildControls();
    439                return ((ListBox)Controls[1]).DataTextField;
    440            }

    441            set
    442            {
    443                this.EnsureChildControls();
    444                ((ListBox)Controls[1]).DataTextField = value;
    445            }

    446
    447        }

    448        public string iDataValueFieldL
    449        {
    450            get
    451            {
    452                this.EnsureChildControls();
    453                return ((ListBox)Controls[1]).DataValueField;
    454            }

    455            set
    456            {
    457                this.EnsureChildControls();
    458                ((ListBox)Controls[1]).DataValueField = value;
    459            }

    460
    461        }

    462        //
    463        public string iDataTextFieldR
    464        {
    465            get
    466            {
    467                this.EnsureChildControls();
    468                return ((ListBox)Controls[11]).DataTextField;
    469            }

    470            set
    471            {
    472                this.EnsureChildControls();
    473                ((ListBox)Controls[11]).DataTextField = value;
    474            }

    475
    476        }

    477        public string iDataValueFieldR
    478        {
    479            get
    480            {
    481                this.EnsureChildControls();
    482                return ((ListBox)Controls[11]).DataValueField;
    483            }

    484            set
    485            {
    486                this.EnsureChildControls();
    487                ((ListBox)Controls[11]).DataValueField = value;
    488            }

    489
    490        }

    491        //iDataBind
    492        public void iDataBindL()
    493        {
    494            this.EnsureChildControls();
    495            ((ListBox)Controls[1]).DataBind();
    496        }

    497        public void iDataBindR()
    498        {
    499            this.EnsureChildControls();
    500            ((ListBox)Controls[11]).DataBind();
    501        }

    502        //得到目前的索引 iSelectIndex
    503        public int iSelectIndexL()
    504        {
    505            this.EnsureChildControls();
    506            int i = ((ListBox)Controls[1]).SelectedIndex;
    507            return i;
    508        }

    509        public int iSelectIndexR()
    510        {
    511            this.EnsureChildControls();
    512            int i = ((ListBox)Controls[11]).SelectedIndex;
    513            return i;
    514        }

    515        //得到ITEM的个数 iCountItem
    516        public int iCountItemL()
    517        {
    518            this.EnsureChildControls();
    519            int i = ((ListBox)Controls[1]).Items.Count;
    520            return i;
    521        }

    522        public int iCountItemR()
    523        {
    524            this.EnsureChildControls();
    525            int i = ((ListBox)Controls[11]).Items.Count;
    526            return i;
    527        }

    528        //添加一个ITEM 到LISTBOX
    529        public void iAddItemL(string addText, string addValue)
    530        {
    531            this.EnsureChildControls();
    532            ListItem temp = new ListItem();
    533            temp.Text = addText.Trim().ToString();
    534            temp.Value = addValue.Trim().ToString();
    535            ((ListBox)Controls[1]).Items.Add(temp);
    536        }

    537        public void iAddItemL(string addText)
    538        {
    539            this.EnsureChildControls();
    540            ListItem temp = new ListItem();
    541            temp.Text = addText.Trim().ToString();
    542            ((ListBox)Controls[1]).Items.Add(temp);
    543        }

    544        public void iAddItemR(string addText, string addValue)
    545        {
    546            this.EnsureChildControls();
    547            ListItem temp = new ListItem();
    548            temp.Text = addText.Trim().ToString();
    549            temp.Value = addValue.Trim().ToString();
    550            ((ListBox)Controls[11]).Items.Add(temp);
    551        }

    552        public void iAddItemR(string addText)
    553        {
    554            this.EnsureChildControls();
    555            ListItem temp = new ListItem();
    556            temp.Text = addText.Trim().ToString();
    557            ((ListBox)Controls[11]).Items.Add(temp);
    558        }

    559        //返回当前所选的Item项
    560        public ListItem iSelectItemL()
    561        {
    562            this.EnsureChildControls();
    563            int index = ((ListBox)Controls[1]).SelectedIndex;
    564            int i = ((ListBox)Controls[1]).Items.Count;
    565            if (index >= 0 && index < i)
    566            {
    567                return ((ListBox)Controls[1]).Items[index];
    568            }

    569            else
    570            {
    571                return null;
    572            }

    573        }

    574        public ListItem iSelectItemR()
    575        {
    576            this.EnsureChildControls();
    577            int index = ((ListBox)Controls[11]).SelectedIndex;
    578            int i = ((ListBox)Controls[11]).Items.Count;
    579            if (index >= 0 && index < i)
    580            {
    581                return ((ListBox)Controls[11]).Items[index];
    582            }

    583            else
    584            {
    585                return null;
    586            }

    587        }

    588        //选择LISTBOX中第index项
    589        public ListItem iSelectItemL(int index)
    590        {
    591            this.EnsureChildControls();
    592            int i = ((ListBox)Controls[1]).Items.Count;
    593            if (index >= 0 && index < i)
    594            {
    595                return ((ListBox)Controls[1]).Items[index];
    596            }

    597            else
    598            {
    599                return null;
    600            }

    601        }

    602        public ListItem iSelectItemR(int index)
    603        {
    604            this.EnsureChildControls();
    605            int i = ((ListBox)Controls[11]).Items.Count;
    606            if (index >= 0 && index < i)
    607            {
    608                return ((ListBox)Controls[11]).Items[index];
    609            }

    610            else
    611            {
    612                return null;
    613            }

    614        }

    615        //清空LISTBOX
    616        public void iClearItemL()
    617        {
    618            this.EnsureChildControls();
    619            ((ListBox)Controls[1]).Items.Clear();
    620        }

    621        public void iClearItemR()
    622        {
    623            this.EnsureChildControls();
    624            ((ListBox)Controls[11]).Items.Clear();
    625        }

    626        //删除目前的所选值
    627        public void iRemoveItemL()
    628        {
    629            this.EnsureChildControls();
    630            int i = ((ListBox)Controls[1]).SelectedIndex;
    631            if (i >= 0)
    632            {
    633                ((ListBox)Controls[1]).Items.Remove(((ListBox)Controls[1]).Items[i]);
    634            }

    635        }

    636        public void iRemoveAtItemL(int index)
    637        {
    638            this.EnsureChildControls();
    639            int i = ((ListBox)Controls[1]).Items.Count;
    640            if (index > 0 && index < i)
    641            {
    642                ((ListBox)Controls[1]).Items.Remove(((ListBox)Controls[1]).Items[index]);
    643            }

    644        }

    645
    646        public void iRemoveItemR()
    647        {
    648            this.EnsureChildControls();
    649            int i = ((ListBox)Controls[11]).SelectedIndex;
    650            if (i >= 0)
    651            {
    652                ((ListBox)Controls[11]).Items.Remove(((ListBox)Controls[11]).Items[i]);
    653            }

    654        }

    655        public void iRemoveAtItemR(int index)
    656        {
    657            this.EnsureChildControls();
    658            int i = ((ListBox)Controls[11]).Items.Count;
    659            if (index > 0 && index < i)
    660            {
    661                ((ListBox)Controls[11]).Items.Remove(((ListBox)Controls[11]).Items[index]);
    662            }

    663        }

    664        //重载宽度
    665        public override Unit Width
    666        {
    667            get
    668            {
    669                return base.Width;
    670            }

    671            set
    672            {
    673                base.Width = value;
    674                this.EnsureChildControls();
    675                ((ListBox)Controls[1]).Width = System.Convert.ToInt32(value.Value * 0.4);
    676                ((ListBox)Controls[11]).Width = System.Convert.ToInt32(value.Value * 0.4);
    677            }

    678        }

    679
    680        //重载高度
    681        public override Unit Height
    682        {
    683            get
    684            {
    685                return base.Height;
    686            }

    687            set
    688            {
    689                base.Height = value;
    690                this.EnsureChildControls();
    691                ((ListBox)Controls[1]).Height = System.Convert.ToInt32(value.Value * 0.98);
    692                ((ListBox)Controls[11]).Height = System.Convert.ToInt32(value.Value * 0.98);
    693            }

    694        }

    695
    696
    697    }
    //class
    698}
    //namespace
    699
  • 相关阅读:
    Sublime3插件安装
    MyEclipse安装后的配置
    JDK 安装与环境变量配置
    Oracle 索引
    Java中间缓存变量机制
    数据库常见考题查询SQL
    python可视化---饼图
    python可视化---直方图的不同形状
    python可视化---堆积直方图
    python可视化---阶梯图step()
  • 原文地址:https://www.cnblogs.com/freeliver54/p/586237.html
Copyright © 2020-2023  润新知