Hi,
We have found a way to fix this problem.
1. The grid should use SessionMode.ViewState to keep it's state data.
2. The IsPostBack property can't be used to determine whether to Initialized the grid. So I use the grid's Submit button to initialize the grid.
3. Set the XhtmlMode to false.
Here is the modified code:
awptest.cs:
------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using System.Web.UI.HtmlControls;
using Aspose.Grid.Web;
using Aspose.Grid.Web.Data;
using System.Data;
using System.Web.UI.WebControls.WebParts;
namespace awptest
{
[XmlRoot(Namespace = "awptest")]
public class awptest : WebPart
{
private GridWeb grid;
protected override void CreateChildControls()
{
base.CreateChildControls();
grid = new GridWeb();
grid.ID = "InnerGrid";
grid.XhtmlMode = false;
grid.SessionMode = SessionMode.ViewState;
grid.SubmitCommand += new WorkbookEventHandler(grid_SubmitCommand);
grid.CustomCommand += new CustomCommandEventHandler(grid_CustomCommand);
Controls.Add(grid);
//if (!Page.IsPostBack)
// InitGrid();
}
private void InitGrid()
{
grid.EditMode = false;
//creating custom buttons
CustomCommandButton cmdChoose = new CustomCommandButton();
cmdChoose.ImageUrl = "/agw_client_debug/save.gif";
cmdChoose.Command = "Choose";
cmdChoose.ToolTip = "Choose";
grid.CustomCommandButtons.Add(cmdChoose);
//init the grid with dataset 0
WebWorksheet sheet = grid.WebWorksheets[0];
DataTable data0 = new DataTable();
data0.Columns.Add("data0");
data0.Rows.Add(new object[] { "0" });
data0.Rows.Add(new object[] { "0" });
sheet.DataSource = data0;
sheet.CreateAutoGenratedColumns();
sheet.DataBind();
}
protected void grid_SubmitCommand(object sender, EventArgs e)
{
InitGrid();
}
private void grid_CustomCommand(object sender, string command)
{
string key = null;
if (grid.ActiveCell != null)
key = (string)grid.ActiveCell.Value;
else
key = "data0";
WebWorksheet sheet = grid.WebWorksheets[0];
//command cases:
if (command == "Choose")
{
//display a choice of dataset for the user to select one
DataTable choice = new DataTable();
sheet.Cells.Clear();
choice.Columns.Add("select one");
choice.Rows.Add(new object[] { "data0" });
choice.Rows.Add(new object[] { "data1" });
sheet.DataSource = choice;
sheet.CreateAutoGenratedColumns();
sheet.DataBind();
grid.CustomCommandButtons[0].Command = "Display";
grid.CustomCommandButtons[0].ToolTip = "Display";
}
if (command == "Display" & key == "data0")
{
//display datset 0
DataTable data0 = new DataTable();
sheet.Cells.Clear();
data0.Columns.Add("data0");
data0.Rows.Add(new object[] { "0" });
data0.Rows.Add(new object[] { "0" });
sheet.DataSource = data0;
sheet.CreateAutoGenratedColumns();
sheet.DataBind();
grid.CustomCommandButtons[0].Command = "Choose";
grid.CustomCommandButtons[0].ToolTip = "Choose";
}
if (command == "Display" & key == "data1")
{
//display dataset 1
DataTable data1 = new DataTable();
sheet.Cells.Clear();
data1.Columns.Add("data1");
data1.Rows.Add(new object[] { "1" });
data1.Rows.Add(new object[] { "1" });
sheet.DataSource = data1;
sheet.CreateAutoGenratedColumns();
sheet.DataBind();
grid.CustomCommandButtons[0].Command = "Choose";
grid.CustomCommandButtons[0].ToolTip = "Choose";
}
}
}
}