protected void btnExport_Click(object sender, EventArgs e) { try { Add_ParameterList('1'); MaintainVCMSLevel BCO = new MaintainVCMSLevel(ConntionDB); DataTable Dt = BCO.QueryVCMSLevelByFind_Export(ParameterList); if (Dt.Rows.Count == 0) { Alert("查無資料"); return; } if (Dt.Columns["ID"] != null) Dt.Columns.Remove("ID"); if (Dt.Columns["CODE"] != null) Dt.Columns.Remove("CODE"); foreach (DataRow dr in Dt.Rows) { for (int i = 0; i < Dt.Columns.Count; i++) { if (Dt.Columns[i].DataType == Type.GetType("System.String")) { dr[i] = string.Format(" {0}", dr[i].ToString()); } if ( (Dt.Columns[i].ColumnName.Trim() == "經銷否") || (Dt.Columns[i].ColumnName.Trim() == "基本功能") || (Dt.Columns[i].ColumnName.Trim() == "銷售情報") || (Dt.Columns[i].ColumnName.Trim() == "研究情報") || (Dt.Columns[i].ColumnName.Trim() == "直往廠商") ) { if (dr[i].ToString().Trim().Replace(" ","") == "1") dr[i] = "是"; else if (dr[i].ToString().Trim().Replace(" ", "") == "0") dr[i] = "否"; } } } Export(System.Text.Encoding.UTF8, "VCMS廠商參加等級與費用_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls", "application/ms-excel", Dt); } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } finally { } }
}//ButtonQuery_Click /// <summary> /// 繫結資料到控制項 /// </summary> /// <param name="vdb"></param> private void databind() { //抓取本頁初次登記的時間 string SessionIDName = "VDM031_" + PageTimeStamp.Value; MaintainVCMSLevel BCO = new MaintainVCMSLevel(ConntionDB); DataTable Dt = BCO.QueryVCMSLevelByFind_Search(ParameterList); DataTable dt = Dt.Copy(); //複製成另一份,因匯出時有加Html空白 Session["VDM031_" + PageTimeStamp.Value] = Dt; GridView1.DataSource = Dt; //設定分頁大小 GridView1.PageSize = (TextBoxPagesize.Text == "") ? 10 : (int.Parse(TextBoxPagesize.Text) < 0) ? 10 : int.Parse(TextBoxPagesize.Text); GridView1.PageIndex = 0; GridView1.DataBind(); #region 將Key值存到Session中 ArrayList arl_Key = new ArrayList(); foreach (DataRow drRow in Dt.Rows) { arl_Key.Add(drRow["ID"].ToString()); } Session["VDM03_SortKey" + PageTimeStamp.Value] = arl_Key; #endregion }//databind