在我的Web应用程序中,我需要在asp.net中使用WebCotrols添加Textbox,Checkbox,Radio按钮等控件。我正在使用案例陈述。 所以任何人都可以告诉我如何做到这一点?
WebControl ObjectToAdd;
switch (obj)
{
case ObjectType.Text:
ObjectToAdd = new TextBox();
break;
case ObjectType.Time:
ObjectToAdd = new Calendar();
break;
case ObjectType.SingleSelect:
ObjectToAdd = new RadioButton();
break;
case ObjectType.Number:
ObjectToAdd = new TextBox();
break;
case ObjectType.MultiSelect:
ObjectToAdd = new CheckBox();
break;
case ObjectType.Date:
ObjectToAdd = new Calendar();
break;
default:
ObjectToAdd = new TextBox();
break;
}
var ChildItemResult = from myRow in dt.AsEnumerable()
where Convert.ToInt32(myRow["RelationParentID"]) == Convert.ToInt32(ViewState["ItemID"])
select myRow;
foreach (var row in ChildItemResult)
{
ObjectToAdd.Attributes.Add ("value" , row["Caption"].ToString());
phContianer.Controls.Add(ObjectToAdd);
}