<ext:Button runat="server" ID="button2" Text="Add the GridPanel" OnDirectClick="button_click"></ext:Button>
<ext:Window runat="server" ID="window1" Width="500" Height="500" Title="Daynamic Add GridPanel">
<TopBar>
<ext:Toolbar runat="server" ID="toolBar1">
<Items>
<ext:Button runat="server" ID="button1" Text="Add the GridPanel" >
<DirectEvents>
<Click OnEvent="button_click">
<EventMask ShowMask="true"
Target="CustomTarget"
CustomTarget="Window1"
/>
</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
</ext:Window>
用创建类对象的方法来创建Ext.Net控件的时候需要注意的问题
一、***ID的属性需要填上否则可能出现xtype未defined的错误在用开发工具调试的时候出现的
二、用Code来创建Ext.Net控件的时候什么时候该用new 的地方 在不熟悉的时候可以通过
在html中用控件的方式来测试下 一般是<ext:Name> <name runat="Server">的时候需要
来new一下
<script runat="server">
//OnDirectClick="button_click"
protected void button_click(object obj, DirectEventArgs args)
{
X.Msg.Alert("error", "error").Show();
BuildGridPanel().AddTo(this.window1);
}
protected void Page_Load(object obj, EventArgs args)
{
// X.Msg.Alert("error", "error").Show();用于测试的
this.BuildStore();
// BuildStore();
}
private Ext.Net.GridPanel BuildGridPanel()
{
return new Ext.Net.GridPanel
{
ID="girdPanel1",
Store = { this.BuildStore() },
ColumnModel =
{
Columns = {
new RowNumbererColumn{
Text="序号"
},
new Column{
DataIndex="username",
Text="username"
},
new Column{
DataIndex="age",
Text="age",
},
new DateColumn
{
DataIndex="birthday",
Text="birthday"
}
}
},
SelectionModel = {
new RowSelectionModel(){ Mode= SelectionMode.Single}
},
View =
{
new Ext.Net.GridView()
{
StripeRows=true,
TrackOver=true
}
}
};
}
private Ext.Net.Store BuildStore()
{
X.Msg.Alert("error", "error").Show();
var store = new Ext.Net.Store
{
ID="store1",
Model = { new Model{
Fields ={
new ModelField("username",ModelFieldType.String),
new ModelField("age",ModelFieldType.Int),
new ModelField("birthday",ModelFieldType.Date,"Y/M/d")
}
}
}
};
store.DataSource = Data;
store.DataBind();
return store;
}
public object[] Data
{
get
{
return new object[]{
new object[]{"Tom",12,"2012/3/3"},
new object[]{"Jack",45,"2012/4/5"},
new object[]{"baler",34,"1990/2/3"}
};
}
}
</script>