p*p 发帖数: 75 | 1 另外一个例子,动态创建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 |
j**o 发帖数: 4 | 2 Before the column is added to the grid, the grid should have been filled with
viewstate data. So adding a blank column with the same name would replace the
column already in there? I have to fire up the Reflector to confirm this. If
so, then the adding column operation should be moved inside the "if" block.
【在 p*p 的大作中提到】 : 另外一个例子,动态创建DataGrid。 同样,随便扔个button可以postback. 运行正常. : private class Employee : { : string id; : string name; : public string Id : { : get { return id; } : } : public string Name
|
b*e 发帖数: 3845 | 3 I guess it's a similar question that has something to do with viewstate.
PIP, you are so strong in .NET. What do you do for a living?
【在 p*p 的大作中提到】 : 另外一个例子,动态创建DataGrid。 同样,随便扔个button可以postback. 运行正常. : private class Employee : { : string id; : string name; : public string Id : { : get { return id; } : } : public string Name
|
k****i 发帖数: 1072 | 4
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() ;
}
【在 p*p 的大作中提到】 : 另外一个例子,动态创建DataGrid。 同样,随便扔个button可以postback. 运行正常. : private class Employee : { : string id; : string name; : public string Id : { : get { return id; } : } : public string Name
|