我头脑发热,无法弄清楚为什么我的数据表在绑定到gridview之前没有保存到会话中?
始终为空。
这是我的代码。 Settings.AutoRedirectMode= RedirectMode,Permanent;
应包含数据。但是,当我去提取gridview排序数据时,它是空的
Session["Data"] = dts;
答案 0 :(得分:1)
你的代码对我来说很好......
protected void Page_Load(object sender, EventArgs e)
{
PopulateOrderList();
}
private void PopulateOrderList()
{
DateTime d;
DateTime d2;
DataTable dts = new DataTable();
dts.Columns.Add("OrderDate", typeof(string));
dts.Columns.Add("OrderNumber", typeof(string));
dts.Columns.Add("OrderItemSKUName", typeof(string));
dts.Columns.Add("SKUNumber", typeof(string));
dts.Columns.Add("OrderItemStatus", typeof(string));
dts.Columns.Add("OrderItemUnitCount", typeof(string));
dts.Columns.Add("mtrx_Code2", typeof(string));
DataRow drNew = dts.NewRow();
drNew["OrderDate"] = DateTime.Now.ToShortDateString();
drNew["OrderNumber"] = "122";
drNew["OrderItemSKUName"] = "sku";
drNew["SKUNumber"] = "skunum";
drNew["OrderItemStatus"] = "Done";
drNew["OrderItemUnitCount"] = "1290";
drNew["mtrx_Code2"] ="abc123";
dts.Rows.Add(drNew);
Session["Data"] = dts;
gridview.Visible = true;
gridview.DataSource = dts.DefaultView;
gridview.DataBind();
}
protected void gridview_SortCommand(object source, DataGridSortCommandEventArgs e)
{
DataTable dt = (DataTable)Session["Data"];
}