标记
<ext:GridPanel ID="GridPanel1" runat="server" Height="300" Title="Title" EnableViewState="true">
<ColumnModel ID="ColumnModel1" runat="server" />
<Store>
<ext:Store ID="Store1" runat="server" EnableViewState="true" />
</Store>
</ext:GridPanel>
代码隐藏
private void BindData(DataTable dataTable, GridPanel gridPanel, Store store)
{
JsonReader jsonReader = new JsonReader();
foreach (DataColumn dataColumn in dataTable.Columns)
{
//Create the column
Ext.Net.Column column = new Column();
column.Header = dataColumn.ColumnName;
column.DataIndex = dataColumn.ColumnName;
gridPanel.ColumnModel.Columns.Add(column);
RecordField recordField = new RecordField();
recordField.Name = dataColumn.ColumnName;
jsonReader.IDProperty = dataColumn.ColumnName;
jsonReader.Fields.Add(recordField);
}
store.Reader.Add(jsonReader);
store.DataSource = dataTable;
store.DataBind();
gridPanel.Reconfigure();
}
DataTable没有问题,但ext.net没有显示任何列或数据。
我的概念是我将从文本框中传递sql select查询,并且网格面板应该自动与我们从select查询接收的数据绑定。我的代码中是否有任何错误,或者我应该怎么做才能在GridPanel中显示动态数据。我使用的是ext.net v1.7。