protected void Page_Load(object sender, EventArgs e) { // create the connection, DataAdapter and DataSet string connectionString = WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString; string sql = "SELECT TOP 5 EmployeeID, TitleOfCourtesy, LastName, FirstName FROM Employees"; SqlConnection conn = new SqlConnection(connectionString); SqlDataAdapter da = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); // Fill the DataSet and fill the first grid. da.Fill(ds, "Employees"); Datagrid1.DataSource = ds.Tables["Employees"]; Datagrid1.DataBind(); // Generate the XML file. string xmlFile = Server.MapPath("Employees.xml"); ds.WriteXml(xmlFile, XmlWriteMode.WriteSchema); // Load the XML file. DataSet dsXml = new DataSet(); dsXml.ReadXml(xmlFile); // Fill the second grid. Datagrid2.DataSource = dsXml.Tables["Employees"]; Datagrid2.DataBind(); }
protected void Button1_Click(object sender, System.EventArgs e) { DataTable messages = new DataTable(); messages.Columns.Add("Subject"); messages.Columns.Add("From"); messages.Columns.Add("Date"); imap41.Server = edtServer.Text; imap41.UserName = edtUser.Text; imap41.Password = edtPassword.Text; imap41.Open(); imap41.SelectMailBox(edtMailBox.Text); for (int i = 1; i <= imap41.CurrentMailBox.ExistsMessages; i++) { imap41.RetrieveHeader(i, mailMessage1); DataRow row = messages.NewRow(); row["Subject"] = mailMessage1.Subject; row["From"] = mailMessage1.From; row["Date"] = mailMessage1.Date; messages.Rows.Add(row); } Datagrid1.DataSource = messages; Datagrid1.DataBind(); imap41.Close(); }
private void InitPage() { BLL.SendMsg send2 = new BLL.SendMsg(); send2.ToUsercode = user.UserCode; send2.State = "1"; send2.todel = "0"; if (send2.GetSendMsgs().Rows.Count > 0) { string code = send2.GetSendMsgs().Rows[0]["SendMsgCode"].ToString(); Response.Redirect("sendmsgview.aspx?MsgCode=" + code + "&Re=true"); } else { BLL.SendMsg send = new BLL.SendMsg(); send.SendUsercode = user.UserCode; send.senddel = "0"; dgList.DataSource = send.GetSendMsgs(); dgList.DataBind(); this.GridPagination1.RowsCount = send.GetSendMsgs().Rows.Count.ToString(); BLL.SendMsg send1 = new BLL.SendMsg(); send1.ToUsercode = user.UserCode; send1.todel = "0"; Datagrid1.DataSource = send1.GetSendMsgs(); Datagrid1.DataBind(); this.GridPagination2.RowsCount = send1.GetSendMsgs().Rows.Count.ToString(); } }
//Filldata Method private void filldata() { ds = new DataSet(); da = new SqlDataAdapter("select * from individual_master ", cn); da.Fill(ds, "individual"); Datagrid1.DataSource = ds; Datagrid1.DataBind(); }
/// <summary> /// 显示发标单位列表 /// </summary> /// <param name="dt"></param> private void BindDataGrid1(DataTable dt) { dgListView.Visible = false; bool useForeignMoney = RmsPM.BLL.BiddingSystem.IsUseForeignMoney(this.BiddingEmitCode); if (!useForeignMoney) { Datagrid1.Columns[6].Visible = false; } Datagrid1.DataSource = dt; Datagrid1.DataBind(); }
private void RefreshGrid() { DataView dv = Epoint.MisBizLogic2.DB.ExecuteDataView("select ItemText,ItemValue from Code_Items inner join Code_Main on Code_Items.CodeID=Code_Main.CodeID where Code_Main.CodeName='RG_会员单位'"); Pager.RecordCount = dv.Count; PagedDataSource pds = new PagedDataSource(); pds.AllowPaging = true; pds.PageSize = Pager.PageSize; pds.CurrentPageIndex = Pager.CurrentPageIndex - 1; pds.DataSource = dv; Datagrid1.DataSource = pds; Datagrid1.DataBind(); LblRecordEveryPage1.Text = "每页:" + "<font color='blue'><b>" + Pager.PageSize.ToString() + "</b></font>"; LblCurrentIndex1.Text = "当前页:" + "<font color='red'><b>" + Pager.CurrentPageIndex.ToString() + "</b></font>"; LblPageCount1.Text = "总页数:" + "<font color='blue'><b>" + Pager.PageCount.ToString() + "</b></font>"; LblRecordCount1.Text = "记录总数:" + "<font color='blue'><b>" + Pager.RecordCount + "</b></font>"; }
protected void Llenar_dtTabla_Inicial() { DataSet ds = new DataSet(); DataRow fila; DBFunctions.Request(ds, IncludeSchema.NO, "SELECT * FROM PPREGUNTAENCUESTA"); if (dtTabla == null) { Cargar_dtTabla(); } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { fila = dtTabla.NewRow(); fila[0] = ds.Tables[0].Rows[i][0].ToString(); fila[1] = ds.Tables[0].Rows[i][1].ToString(); dtTabla.Rows.Add(fila); Datagrid1.DataSource = dtTabla; Datagrid1.DataBind(); Session["dtTabla"] = dtTabla; } }
//This is used to show the data in report. public void show() { grdLeg.Visible = true; int x = 0; object op = null; System.Data.SqlClient.SqlDataReader rdr = null; string sql = "select distinct productid from stock_master"; // Calls the sp_stockmovement for each product and create one stkmv temp. table. dbobj.SelectQuery(sql, ref rdr); while (rdr.Read()) { dbobj.ExecProc(OprType.Insert, "sp_stockmovement", ref op, "@id", Int32.Parse(rdr["productid"].ToString()), "@strfromdate", getdate(txtDateFrom.Text, true).Date.ToShortDateString(), "@strtodate", getdate(txtDateTo.Text, true).Date.ToShortDateString()); } rdr.Close(); dbobj.SelectQuery("select * from stkmv", ref rdr); if (rdr.HasRows) { grdLeg.DataSource = rdr; grdLeg.DataBind(); grdLeg.Visible = false; } //*********************** rdr.Close(); dbobj.SelectQuery("select * from stkmv where category='Ibp grade'", ref rdr); if (rdr.HasRows) { Datagrid1.DataSource = rdr; Datagrid1.DataBind(); Datagrid1.Visible = false; } rdr.Close(); dbobj.SelectQuery("select * from stkmv where category='Eicher grade'", ref rdr); if (rdr.HasRows) { Datagrid2.DataSource = rdr; Datagrid2.DataBind(); Datagrid2.Visible = false; } rdr.Close(); dbobj.SelectQuery("select * from stkmv where category='Force grade'", ref rdr); if (rdr.HasRows) { Datagrid3.DataSource = rdr; Datagrid3.DataBind(); Datagrid3.Visible = false; } if (eicher != 0) { eicher1 = "-" + eicher; } if (force != 0) { force1 = "-" + force; } if (sales1 != 0) { ibp1 = "-" + sales1; } grandtotal = sales - sales1 - eicher - force; //*********************** // truncate table after use. dbobj.Insert_or_Update("truncate table stkmv", ref x); }
private void filldata() { Datagrid1.DataSource = ds; Datagrid1.DataBind(); }
protected void excel_Vers_XML(Object Sender, EventArgs e) { string[] TabChaine = new string[20]; int i = 0; String Fournisseur = "Provider=Microsoft.Jet.OLEDB.4.0"; String Adresse_Donnees = "Data Source=" + path + "excel_projet.xls"; // TMP_EXCl_DEC2015.xls"; String Outils_Concernes = " Extended Properties=Excel 8.0"; String Specification_Connexion = Fournisseur + ";" + Adresse_Donnees + ";" + Outils_Concernes; OleDbConnection Obj_Interop = new OleDbConnection(Specification_Connexion); Obj_Interop.Open(); DataTable dtExcelSchema; //Obtenir le Schema du fichier Excel dtExcelSchema = Obj_Interop.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string Nom_Tab_Excl = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString(); OleDbCommand Cmnd_Selection = new OleDbCommand("SELECT * FROM [" + Nom_Tab_Excl + "]", Obj_Interop); // Créér un adaptateur pour récupérer les valeurs des cellules Excel OleDbDataAdapter Adaptateur_Recp_Donnees = new OleDbDataAdapter(); // transfert des données depuis le fichier Execl vers l'adaptateur Adaptateur_Recp_Donnees.SelectCommand = Cmnd_Selection; DataSet Ens_Donnees = new DataSet(); // remplir le Data Set avec le contenu de l'adaptateur Adaptateur_Recp_Donnees.Fill(Ens_Donnees); Datagrid1.DataSource = Ens_Donnees.Tables[0].DefaultView; // la structure 'Web Form' type Datagrid1 est chargé du contenu du Data Set (Ensemble flexible des Donnees) Datagrid1.DataBind(); Response.Write("<center>"); int k = -1; foreach (DataRow DdL in Ens_Donnees.Tables[0].Rows) { k = k + 1; nom = DdL[0].ToString(); // accès à chaque colonne i = 0; //affichage foreach (Object v in DdL.ItemArray) { TabChaine[i] = v.ToString(); if (TabChaine[i] != nullStr) { // if ((TabChaine[i].Length != 0)) //{ Response.Write("<br><hr width='30%'> TabChaine[" + k + "," + i + "] = " + TabChaine[i]); } i = i + 1; } } // TabChaine[i] = nom; // Response.Write("<br><hr>" + nom); Label1.Text = nom; prenom = DdL[1].ToString(); } using (XmlWriter writer = XmlWriter.Create(path + "excel_xml.xml")) { writer.WriteStartDocument(); writer.WriteStartElement("PROJET"); foreach (DataRow DdL in Ens_Donnees.Tables[0].Rows) { if (DdL[0].ToString() != nullStr) { writer.WriteStartElement("individu"); writer.WriteElementString("id", DdL[0].ToString()); writer.WriteElementString("nom", DdL[1].ToString()); writer.WriteElementString("prenom", DdL[2].ToString()); writer.WriteEndElement(); } } writer.WriteEndDocument(); } Obj_Interop.Close(); }
protected void lnkbtnGenrateToExcel_Click(object sender, System.EventArgs e) { try { dgReport.CurrentPageIndex = 0; showResolutionTimeReport(); clsResolutionTimeReport objClsResolutionTimeReport = new clsResolutionTimeReport(); objClsResolutionTimeReport.EmployeeID = SAEmployeeID; strFileNameCust = "Report_" + objClsResolutionTimeReport.EmployeeID + ".xls"; // DataGrid dgForCSVFile = new DataGrid(); // DataView dv = new DataView(); //if(dsResolutionTimeReport.Tables[0].Rows.Count>0) // { #region Commented code // dgForCSVFile.AutoGenerateColumns = false; // BoundColumn ReportIssueID = new BoundColumn(); // ReportIssueID.HeaderText = "Issue ID"; // ReportIssueID.DataField = "ReportIssueID"; // dgForCSVFile.Columns.Add(ReportIssueID); // // dgForCSVFile.AutoGenerateColumns = false; // BoundColumn ReportedBy = new BoundColumn(); // ReportedBy.HeaderText = "Reported By"; // ReportedBy.DataField = "ReportedBy"; // dgForCSVFile.Columns.Add(ReportedBy); // // dgForCSVFile.AutoGenerateColumns = false; // BoundColumn ReportedOn = new BoundColumn(); // ReportedOn.HeaderText = "Reported On"; // ReportedOn.DataField = "ReportedOn"; // dgForCSVFile.Columns.Add(ReportedOn); // // dgForCSVFile.AutoGenerateColumns = false; // BoundColumn AssignedTo = new BoundColumn(); // AssignedTo.HeaderText = "Issue ID"; // AssignedTo.DataField = "AssignedTo"; // dgForCSVFile.Columns.Add(AssignedTo); // // dgForCSVFile.AutoGenerateColumns = false; // BoundColumn ResolvedOn = new BoundColumn(); // ResolvedOn.HeaderText = "Resolved On"; // ResolvedOn.DataField = "ResolvedOn"; // dgForCSVFile.Columns.Add(ResolvedOn); // // dgForCSVFile.AutoGenerateColumns = false; // BoundColumn StatusID = new BoundColumn(); // StatusID.HeaderText = "Status ID"; // StatusID.DataField = "StatusID"; // dgForCSVFile.Columns.Add(StatusID); // // dgForCSVFile.AutoGenerateColumns = false; // BoundColumn ResolutionTime = new BoundColumn(); // ResolutionTime.HeaderText = "Resolution Time"; // ResolutionTime.DataField = "ResolutionTime"; // dgForCSVFile.Columns.Add(ResolutionTime); // // dgForCSVFile.AutoGenerateColumns = false; // TemplateColumn ResolutionHealth = new TemplateColumn(); // Label lblResolutionHealth = new Label(); // //BoundColumn ResolutionHealth = new BoundColumn(); // ResolutionHealth.HeaderText = "Resolution Health"; // lblResolutionHealth.Text = DataBinder.Eval(Container.DataItem,"ResolutionHealth"); // // dgForCSVFile.Columns.Add(ResolutionHealth); // #endregion Commented code // Datagrid1.DataSource = dsResolutionTimeReport;//.Tables[0]; // Datagrid1.DataBind(); // } if (dv.Count > 0) { Datagrid1.DataSource = dv;//.Tables[0]; Datagrid1.DataBind(); } Response.Clear(); Response.Charset = ""; Response.AddHeader("content-disposition", "attachment;FileName = " + strFileNameCust); Response.ContentType = "application/vnd.ms-excel"; StringWriter objStringWriter = new StringWriter(); System.Web.UI.HtmlTextWriter objHtmlTextWriter = new HtmlTextWriter(objStringWriter); Datagrid1.RenderControl(objHtmlTextWriter); Response.Write(objStringWriter.ToString()); Response.End(); } catch (System.Threading.ThreadAbortException ex) { } catch (V2Exceptions ex) { throw; } catch (System.Exception ex) { FileLog objFileLog = FileLog.GetLogger(); objFileLog.WriteLine(LogType.Error, ex.Message, "ResolutionTimeReport.aspx", "lnkbtnGenrateToExcel_Click", ex.StackTrace); throw new V2Exceptions(ex.ToString(), ex); } }
protected void Bind_Datas_dtTabla() { Datagrid1.DataSource = dtTabla; Datagrid1.DataBind(); Session["dtTabla"] = dtTabla; }