EditorPart衍生类
public class ToolPanl : EditorPart
{
protected Table tabCategory;
protected DropDownList dplOptionList;
protected DropDownList dplResultList;
protected TextBox txtRemark;
protected TextBox txtCount;
protected RadioButtonList rblQuestionRandom;
protected RadioButtonList rblOptionRandom;
public ToolPanl()
{
this.ID = "pandaToolPanl";
}
public override bool ApplyChanges()
{
OnlineLearn pt = WebPartToEdit as OnlineLearn;
pt.SourceList = this.dplOptionList.SelectedValue;
pt.ResultList = this.dplResultList.SelectedValue;
pt.QuestionCount = int.Parse(this.txtCount.Text);
pt.QuestionRandom = bool.Parse(this.rblQuestionRandom.SelectedValue);
pt.OptionRandom = bool.Parse(this.rblOptionRandom.SelectedValue);
pt.QuestionRemark = this.txtRemark.Text;
return true;
}
public override void SyncChanges()
{
EnsureChildControls();
OnlineLearn pt = WebPartToEdit as OnlineLearn;
pt.SourceList = this.dplOptionList.SelectedValue;
pt.ResultList = this.dplResultList.SelectedValue;
pt.QuestionCount = int.Parse(this.txtCount.Text);
pt.QuestionRandom = bool.Parse(this.rblQuestionRandom.SelectedValue);
pt.OptionRandom = bool.Parse(this.rblOptionRandom.SelectedValue);
pt.QuestionRemark = this.txtRemark.Text;
}
protected override void CreateChildControls()
{
OnlineLearn pt = WebPartToEdit as OnlineLearn;
this.tabCategory = new Table();
this.tabCategory.Width = new Unit("100%");
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.Add(new LiteralControl("<b>Select List For Question :</b>"));
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
this.dplOptionList = new DropDownList();
this.dplOptionList.ID = "drpOption";
this.dplOptionList.CssClass = "pd-toolpanl";
SPListCollection lists= SPContext.Current.Web.Lists;
foreach (SPList item in lists)
{
this.dplOptionList.Items.Add(new ListItem(item.Title));
}
this.dplOptionList.SelectedValue = pt.SourceList;
cell.Controls.Add(dplOptionList);
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
cell.Controls.Add(new LiteralControl("<b>Select List For Result :</b>"));
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
this.dplResultList = new DropDownList();
this.dplResultList.ID = "dplResult";
this.dplResultList.CssClass = "pd-toolpanl";
lists = SPContext.Current.Web.Lists;
foreach (SPList item in lists)
{
this.dplResultList.Items.Add(new ListItem(item.Title));
}
this.dplResultList.SelectedValue = pt.ResultList;
cell.Controls.Add(dplResultList);
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
cell.Controls.Add(new LiteralControl("<b>Question Random :</b>"));
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
this.rblQuestionRandom = new RadioButtonList();
this.rblQuestionRandom.Items.Add(new ListItem("Yes", "true"));
this.rblQuestionRandom.Items.Add(new ListItem("No", "false"));
this.rblQuestionRandom.RepeatDirection = RepeatDirection.Horizontal;
this.rblQuestionRandom.RepeatLayout = RepeatLayout.Flow;
this.rblQuestionRandom.SelectedIndex = pt.QuestionRandom ? 0 : 1;
cell.Controls.Add(this.rblQuestionRandom);
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
cell.Controls.Add(new LiteralControl("<b>Answer Random :</b>"));
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
this.rblOptionRandom = new RadioButtonList();
this.rblOptionRandom.Items.Add(new ListItem("Yes", "true"));
this.rblOptionRandom.Items.Add(new ListItem("No", "false"));
this.rblOptionRandom.RepeatDirection = RepeatDirection.Horizontal;
this.rblOptionRandom.RepeatLayout = RepeatLayout.Flow;
this.rblOptionRandom.SelectedIndex = pt.OptionRandom ? 0 : 1;
cell.Controls.Add(this.rblOptionRandom);
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
cell.Controls.Add(new LiteralControl("<b>Question Count :</b>"));
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
this.txtCount = new TextBox();
this.txtCount.BorderStyle = BorderStyle.Groove;
this.txtCount.Width = new Unit(30);
this.txtCount.Text = pt.QuestionCount.ToString();
cell.Controls.Add(txtCount);
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
cell.Controls.Add(new LiteralControl("<b>Question Remark :</br>"));
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
this.txtRemark = new TextBox();
this.txtRemark.TextMode = TextBoxMode.MultiLine;
this.txtRemark.Rows = 4;
this.txtRemark.BorderStyle = BorderStyle.Groove;
this.txtRemark.Width = new Unit("80%");
this.txtRemark.Text = pt.QuestionRemark;
cell.Controls.Add(txtRemark);
row.Cells.Add(cell);
this.tabCategory.Rows.Add(row);
this.Controls.Add(this.tabCategory);
}
protected override void Render(HtmlTextWriter writer)
{
this.tabCategory.RenderControl(writer);
}
protected override void OnInit(EventArgs e)
{
this.EnsureChildControls();
base.OnInit(e);
}