avatar
ASP.NET 难题测试 (2)# DotNet - 窗口里的风景
p*p
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
avatar
j*o
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

avatar
b*e
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

avatar
k*i
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

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。