当前位置:文档之家› 自定义表格控件使用说明

自定义表格控件使用说明

本文档用于在U9里插入表格,并在表格中动态生成多种控件,支持单选、多选、文本框和多控件混杂。

原理:先用vs开发自定义服务器控件,然后在UBF里放置label控件进行定位,通过代码new自定义控件,再替换掉label。

1.实现效果预览2.服务器控件开发可以在百度上搜索服务器控件开发,代码可以参照以下附件UFIDA.U9.Cust.SGS.PERLAII.PUB.rar如果不需要修改控件,可跳过该本环节。

3.放置Label控件从控件列表拖一个label到页面,并设置大小。

注意:控件的最大长宽,取决于label的长宽。

4.动态生成代码并替换UBF构造并自动生成解决方案,如下:引入控件,选择UFIDA.U9.Cust.SGS.PERLAII.PUB.ReviewSheet.dll,点击确认即可。

在SubjectUIFormWebPartCodeBehindExtend.cs的函数AfterCreateChildControls()里进行控件新增和替换。

ReviewSheet rs;rs = new ReviewSheet();//构造标题列表List<string> headlist = new List<string>();headlist.Add("Item to be checked");headlist.Add ("Evaluation");headlist.Add("Reviewer");headlist.Add("Certifier Remarks");headlist.Add("Certifier");headlist.Add("Guideline");//控件头赋值rs.headlist = headlist;//构造行哈希表,表key为列号,value为控件集合Hashtable hshTable = new Hashtable();//第一行第一列,文本List<WebControl> controllist1 = new List<WebControl>();Label lb1 = new Label();lb1.Text = "Offer/application";controllist1.Add(lb1);hshTable.Add(0, controllist1);//第一行第二列,输入框textboxList<WebControl> controllist2 = new List<WebControl>();Label lb2 = new Label();lb2.Text = "in project folder and in PERLA ?";controllist2.Add(lb2);TextBox textbox1 = new TextBox();textbox1.ID = "textbox1";controllist2.Add(textbox1);hshTable.Add(1, controllist2);//第一行第三列,文本和单选框,要设置id,text,groupnameList<WebControl> controllist3 = new List<WebControl>();Label lb3 = new Label();lb3.Text = "latest ed./amd. applied:";controllist3.Add(lb3);RadioButton rbY = new RadioButton();rbY.ID = "RadioButtonY";rbY.Text = "YES";rbY.GroupName = "RBGroup1";controllist3.Add(rbY);RadioButton rbN = new RadioButton();rbN.ID = "RadioButtonN";rbN.Text = "NO";rbN.GroupName = "RBGroup1";controllist3.Add(rbN);hshTable.Add(2, controllist3);//第一行第四列,文本和多选框混合,设置id,textList<WebControl> controllist4 = new List<WebControl>();Label lb4 = new Label();lb4.Text = "Evidence: ";controllist4.Add(lb4);CheckBox checkbox1 = new CheckBox();checkbox1.ID = "checkbox1";checkbox1.Text = "signature";controllist4.Add(checkbox1);CheckBox checkbox2 = new CheckBox();checkbox2.ID = "checkbox2";checkbox2.Text = "email";controllist4.Add(checkbox2);CheckBox checkbox3 = new CheckBox();checkbox3.ID = "checkbox3";checkbox3.Text = "in PERLA";controllist4.Add(checkbox3);hshTable.Add(3, controllist4);//第一行第五列,单选和本文输入框混合,当选择rbother时,textbox才允许输入List<WebControl> controllist5 = new List<WebControl>();RadioButton rbEnglish = new RadioButton();rbEnglish.ID = "RadioButtonEnglish";rbEnglish.Text = "English";rbEnglish.GroupName = "RBGroup5";rbEnglish.AutoPostBack = true;controllist5.Add(rbEnglish);//写other的checkchanged事件RadioButton rbOther = new RadioButton();rbOther.ID = "RadioButtonOther";rbOther.Text = "Other";rbOther.GroupName = "RBGroup5";rbOther.AutoPostBack = true;rbOther.CheckedChanged += new EventHandler(rbOther_CheckedChanged);controllist5.Add(rbOther);TextBox textOther = new TextBox();textOther.ID = "textOther";controllist5.Add(textOther);hshTable.Add(4, controllist5);////第一行第六列,如果该列无任何控件,要留空hshTable.Add(5, null);//控件行赋值rs.AddRow(hshTable);//控件替换,替换原来的lableUFIDA.U9.CS.UI.PDHelper.WebpartHelper.ReplaceControl(bel110, rs, this.Card2);5.子控件事件触发可以在新增子控件时,编写子控件的触发事件,如果是checkbox、RadioButton这些控件要注意把AutoPostBack属性改为true,如果不需要触发事件,设置为false,避免产生页面交互。

//写other的checkchanged事件RadioButton rbOther = new RadioButton();rbOther.ID = "RadioButtonOther";rbOther.Text = "Other";rbOther.GroupName = "RBGroup5";rbOther.AutoPostBack = true;rbOther.CheckedChanged += new EventHandler(rbOther_CheckedChanged);//重点这句话controllist5.Add(rbOther);void rbOther_CheckedChanged(object sender, EventArgs e){//throw new NotImplementedException();//在此写逻辑代码}6.子控件的取值、赋值可以使用控件函数FindControlByID查找到相关子控件,进行控件类型转换后,如常用控件一般使用即可。

TextBox tb = (TextBox)(rs.FindControlByID("textbox1"));string str = tb.Text;源代码附件:SubjectUI.rar7.部署修改AutoBuild.bat文件,把控件dll拷贝到UILib目录下。

8.注意事项●控件内部子控件的命名。

由于子控件的赋值、取值、触发事件,都是通过控件ID进行查找的,要注意控件ID不能重复,如果一个页面放多个控件,子控件的ID建议使用控件名+子控件名方式,如:rs1_textbox1,rs2_checkbox1等。

●由于控件是使用table进行排版,所以标题数和表格数要一致。

例如表格如果有6列,则标题必须要6个、表体行的哈希表也必须要有6个值,否则产生错位。

如:List<string> headlist = new List<string>();//6个标题,代表6列headlist.Add("Item to be checked");headlist.Add ("Evaluation");headlist.Add("Reviewer");headlist.Add("Certifier Remarks");headlist.Add("Certifier");headlist.Add("Guideline");//一个哈希表代表一行,哈希表必须有6个元素,代表6列,如果某列没控件,也必须赋值null,如hshTable.Add(5, null);Hashtable hshTable = new Hashtable();hshTable.Add(0, controllist1);hshTable.Add(1, controllist2);hshTable.Add(2, controllist3);hshTable.Add(3, controllist4);hshTable.Add(4, controllist5);hshTable.Add(5, controllist6);rs.AddRow(hshTable);。

相关主题