Nov 18, 2016, 2:52 AM
When updated GridPanel.GetStore().DataSource, the page doesn't show the store
Last edited by eko; Nov 18, 2016 at 3:01 AM.
[code][/code]
tags? :)<%@ Page Language="C#" AutoEventWireup="true" CodeFile="InfoConfiguration.aspx.cs" Inherits="InfoConfiguration" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>ä¿¡æ¯é…ç½®</title>
<script>
function insertRecord(grid) {
var store = grid.store,
row = store.indexOf(store.insert(0, { SerialNum: 0 })[0]);
Ext.defer(function () {
grid.editingPlugin.startEditByPosition({ row: row, column: 1 });
}, 100);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager runat="server" />
<ext:GridPanel runat="server" ID="Info_Grid" ColumnLines="true" Height="600" >
<Store>
<ext:Store runat="server" ID="storeInfo" OnSubmitData="storeInfo_SubmitData">
<Model>
<ext:Model ID="UserInfoModel" runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="SerialNum" Type="Int"></ext:ModelField>
<ext:ModelField Name="Phone" Type="String"></ext:ModelField>
<ext:ModelField Name="Status" Type="String"></ext:ModelField>
<ext:ModelField Name="Judge" Type="String"></ext:ModelField>
<ext:ModelField Name="Value" Type="String"></ext:ModelField>
<ext:ModelField Name="Type" Type="String"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<SelectionModel>
<ext:RowSelectionModel runat="server" Mode="Multi"></ext:RowSelectionModel>
</SelectionModel>
<ColumnModel>
<Columns>
<ext:Column runat="server" ID="columnSerialNum" Width="70" Text="åºå·" DataIndex="SerialNum">
<Editor>
<ext:TextField runat="server" Editable="false"></ext:TextField>
</Editor>
</ext:Column>
<ext:Column runat="server" ID="columnPhone" Width="300" Text="电è¯å·ç*" DataIndex="Phone">
<Editor>
<ext:TextField runat="server"></ext:TextField>
</Editor>
</ext:Column>
<ext:Column runat="server" ID="columnStatus" Width="250" Text="问题æè¿°" DataIndex="Status">
<Editor>
<ext:TextField runat="server"></ext:TextField>
</Editor>
</ext:Column>
<ext:Column runat="server" ID="columnJudge" Width="250" Text="测点判æ–*" DataIndex="Judge">
<Editor>
<ext:TextField runat="server"></ext:TextField>
</Editor>
</ext:Column>
<ext:Column runat="server" ID="columnSecond" Width="150" Text="秒数/超é™å€¼" DataIndex="Value">
<Editor>
<ext:TextField runat="server"></ext:TextField>
</Editor>
</ext:Column>
<ext:Column runat="server" ID="column1" Width="150" Text="类型" DataIndex="Type">
<Editor>
<ext:TextField runat="server"></ext:TextField>
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<BottomBar>
<ext:Toolbar ID="Toolbar5" runat="server">
<Items>
<ext:ToolbarFill MaxWidth="330" runat="server" />
<ext:Button ID="AddRow" runat="server" Text="æ·»åŠ*è¡Œ" Width="100" Icon="Add">
<Listeners>
<Click Handler="insertRecord(#{Info_Grid});" />
</Listeners>
</ext:Button>
<ext:Button ID="DeleteRow" runat="server" Text="åˆ*除行" Width="100" Icon="Delete">
<Listeners>
<Click Handler="#{Info_Grid}.deleteSelected();" />
</Listeners>
</ext:Button>
<ext:Button ID="Save" runat="server" Text="ä¿å*˜" Width="100" Icon="Disk">
<Listeners>
<Click Handler="#{Info_Grid}.submitData();" AutoPostBack="true" />
</Listeners>
</ext:Button>
<ext:ToolbarFill runat="server" />
</Items>
</ext:Toolbar>
</BottomBar>
<Plugins>
<ext:CellEditing runat="server" />
<%--ext:RowEditing runat="server" ClicksToEdit="1"></--%>
</Plugins>
</ext:GridPanel>
</div>
</form>
</body>
</html>
cs codeusing System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
public partial class InfoConfiguration : System.Web.UI.Page
{
protected static string ALARM_PATH = System.Configuration.ConfigurationManager.AppSettings["Alarm_Path"].ToString();
protected static List<object> DataSrc;
protected static List<InfoUnit> DstData;
protected static string[] head = { "电è¯å·ç*", "问题æè¿°", "测点判æ–*", "秒数/超é™å€¼", "类型" };
protected static string[] datas = null;
protected void Page_Load(object sender, EventArgs e)
{
//if (!IsPostBack)
//{
// InputData();
// LoadGrid();
//}
InputData();
LoadGrid();
}
protected void LoadGrid()
{
Info_Grid.GetStore().DataSource = DataSrc;
Info_Grid.SetWidth("100%");
}
protected void LoadGrid(List<InfoUnit> DstData)
{
DataSrc = DstData.OfType<object>().ToList();
Info_Grid.GetStore().DataSource = DataSrc;
Info_Grid.SetWidth("100%");
}
protected void InputData()
{
try
{
if (File.Exists(ALARM_PATH))
{
datas = File.ReadAllLines(ALARM_PATH, System.Text.Encoding.Default);
if (datas == null) return;
DataSrc = new List<object>();
for (int i = 1; i < datas.Length; i++)
{
string[] data = datas[i].Split(new char[] { ',', ',' });
if (data.Length != 5) continue;
DataSrc.Add(new InfoUnit() { SerialNum = i, Phone = data[0], Status = data[1], Judge = data[2], Value = data[3], Type = data[4] });
}
}
}
catch (Exception ex)
{
}
}
protected void OutputData()
{
try
{
if (DataSrc == null) return;
StreamWriter sw = new StreamWriter(ALARM_PATH, false, System.Text.Encoding.Default);
sw.WriteLine(head[0] + "," + head[1] + "," + head[2] + "," + head[3] + "," + head[4]);
foreach (InfoUnit info in DstData)
{
sw.WriteLine(string.Format("{0}, {1}, {2}, {3}, {4}", info.Phone, info.Status, info.Judge, info.Value, info.Type));
}
sw.Close();
}
catch (Exception ex)
{
}
}
protected void storeInfo_SubmitData(object sender, StoreSubmitDataEventArgs e)
{
DstData = e.Object<InfoUnit>();
OutputData();
//LoadGrid(DstData);
//Info_Grid.Reload();
Page_Load(null, null);
}
}
datas = @"phone, status, jusdge, value, type
13750029337, statusOne, 001;002, 500000, typeOne
phoneTwo, statusTwo, 002;003, 500002, typeTwo
phoneThree, statusThree, 003;004, 500003, typeThree";