由买买提看人间百态

topics

全部话题 - 话题: htmlform
(共0页)
p*p
发帖数: 75
1
来自主题: DotNet版 - ASP.NET 难题测试 (1)
看到几个有趣的问题,如果不看ASP.NET source code, 几乎就无法解决。
private void Page_Load(object sender, System.EventArgs e)
{
DropDownList ddlDynamic = new DropDownList();
ddlDynamic.ID = "ddlDynamic";
HtmlForm form1 = (HtmlForm)this.FindControl("Form1");
if (!IsPostBack)
{
ddlDynamic.Items.Add("Before");
}
form1.Controls.Add(ddlDynamic);
if (!IsPostBack)
{
ddlDynamic.Items.Add("After");
}
}
在Page上扔个Button,
p*p
发帖数: 75
2
来自主题: DotNet版 - ASP.NET 难题测试 (2)
另外一个例子,动态创建DataGrid。 同样,随便扔个button可以postback. 运行正常.
private class Employee
{
string id;
string name;
public string Id
{
get { return id; }
}
public string Name
{
get { return name; }
}
public Employee(string id, string name)
{
this.id = id;
this.name = name;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
DataGrid grid = new DataGrid() ;
HtmlForm form1 = (HtmlForm)this.FindControl("Form1");
form1.Controls .Add(grid);
if (!IsPostBack)
{
Employee[] people = new Employee[] { new Emp
k****i
发帖数: 1072
3
来自主题: DotNet版 - ASP.NET 难题测试 (2)

DataGrid grid = new DataGrid() ;
grid.AutoGenerateColumns = false;
BoundColumn column = new BoundColumn() ;
column.HeaderText = "Name";
column.DataField = "Name";
grid.Columns.Add(column);
HtmlForm form1 = (HtmlForm)this.FindControl("Form1");
form1.Controls .Add(grid);
if (!IsPostBack)
{
Employee[] people = new Employee[] { new Employee("1", "Steve") , new
Employee("2", "John") , } ;
grid.DataSource = people;
grid.DataBind() ;
}
(共0页)