/// <summary> /// Check if there is more thant 0 links controls in a control or if this control is a link /// </summary> /// <param name="control">control to check in</param> /// <returns>true if there is any links</returns> public static bool ContainsLink(Control control) { bool ret = false; // search a link in the cell Control ctrl = ContainsControlType(control, typeof(HyperLink), typeof(LinkButton), typeof(DataBoundLiteralControl), typeof(TextBox), typeof(DropDownList)); // if a control is returned, we have to check the case of the literal which could contain no links if (ctrl != null) { if (ctrl.GetType().Equals(typeof(DataBoundLiteralControl))) { DataBoundLiteralControl dblc = (DataBoundLiteralControl)ctrl; // here I check if the text contains a href or onclick attribute // I assume that there this text should not be used to be displayed if (dblc.Text.Contains("href") || dblc.Text.Contains("onclick")) { ret = true; } } else { ret = true; } } return(ret); }
// ********************************************************************* // // FinishDataBinding Event Handler // /// <summary> /// This event handler is called when the DataList's DataBound method is /// called. This event handler needs to add the DataBoundStrings to the /// DataListItem. Since the ImageButtons break up the DataBinding Literal /// and DataBound strings, we have two functions: BeginDataBinding and /// FinishDataBinding. This one, finish, is responsible for the databound /// content AFTER the imageButtons. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> // // ********************************************************************/ private void FinishDataBinding(Object sender, EventArgs e) { DataBoundLiteralControl target = (DataBoundLiteralControl)sender; DataListItem Container = (DataListItem)target.NamingContainer; // Add the DataBoundStrings target.SetDataBoundString(0, Convert.ToString(DataBinder.Eval(Container.DataItem, "PostID"))); target.SetDataBoundString(1, DataBinder.Eval(Container.DataItem, "Subject").ToString()); // we have to add other strings if we need to show the username / dateposted if (ShowUsername) { // we need to show the username target.SetDataBoundString(2, Context.Server.UrlEncode(DataBinder.Eval(Container.DataItem, "Username").ToString())); target.SetDataBoundString(3, DataBinder.Eval(Container.DataItem, "Username").ToString()); // we need to show the username AND the DatePosted if (ShowDatePosted) { target.SetDataBoundString(4, Users.AdjustForTimezone(Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "PostDate", "{0:g}")), iUserTimezone)); } // we need to show JUST the DatePosted } else if (ShowDatePosted) { target.SetDataBoundString(2, Users.AdjustForTimezone(Convert.ToDateTime(DataBinder.Eval(Container.DataItem, "PostDate", "{0:g}")), iUserTimezone)); } }
static int GetIndex(System.Web.UI.Page page) { // insert global scripts just before first script tag in the header // or after last css style tag if no script tags in the header found int cnt = 0; int idx = 0; string ctrlText = ""; foreach (Control ctrl in page.Header.Controls) { cnt++; try { if (ctrl.GetType() == typeof(LiteralControl)) { LiteralControl lc = (LiteralControl)ctrl; ctrlText = lc.Text.ToLower(); } if (ctrl.GetType() == typeof(Literal)) { Literal lc = (Literal)ctrl; ctrlText = lc.Text.ToLower(); } if (ctrl.GetType() == typeof(DataBoundLiteralControl)) { DataBoundLiteralControl lc = (DataBoundLiteralControl)ctrl; ctrlText = lc.Text.ToLower(); } if (ctrl.GetType() == typeof(HtmlLink)) { HtmlLink hl = (HtmlLink)ctrl; if (!string.IsNullOrEmpty(hl.Attributes["type"])) { ctrlText = hl.Attributes["type"].ToLower(); } } if (ctrlText.Contains("text/css")) { idx = cnt; } if (ctrlText.Contains("text/javascript")) { idx = cnt; // offset by 1 as we need inject before if (idx > 1) { idx = idx - 1; } break; } } catch { break; } } return(idx); }
// ********************************************************************* // // BeginDataBinding Event Handler // /// <summary> /// This event handler is called when the DataList's DataBound method is /// called. This event handler needs to add the DataBoundStrings to the /// DataListItem. Since the ImageButtons break up the DataBinding Literal /// and DataBound strings, we have two functions: BeginDataBinding and /// FinishDataBinding. This one, begin, is responsible for the databound /// content BEFORE the imageButtons. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> // // ********************************************************************/ private void BeginDataBinding(Object sender, EventArgs e) { DataBoundLiteralControl target = (DataBoundLiteralControl)sender; DataListItem Container = (DataListItem)target.NamingContainer; // Add the DataBoundString target.SetDataBoundString(0, DisplayIndent(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "PostLevel")))); }
public void Deny_Unrestricted() { DataBoundLiteralControl dblc = new DataBoundLiteralControl(1, 1); dblc.SetDataBoundString(0, "mono"); dblc.SetStaticString(0, "monkey"); Assert.AreEqual("monkeymono", dblc.Text, "Text"); }
public void ITextControl_Deny_Unrestricted() { ITextControl tc = new DataBoundLiteralControl(1, 1); Assert.AreEqual(String.Empty, tc.Text, "ITextControl.Text"); // setter throw tc.Text = "singe"; }
// Return true if actually wrote any head elements. If called with // null, this returns whether head elements would be written if called // with a real writer. /// <include file='doc\HtmlFormAdapter.uex' path='docs/doc[@for="HtmlFormAdapter.RenderExtraHeadElements"]/*' /> protected virtual bool RenderExtraHeadElements(HtmlMobileTextWriter writer) { bool result = false; String metaTagName = Device.RequiredMetaTagNameValue; if (metaTagName != null) { if (writer != null) { writer.Write("<meta NAME=\"" + metaTagName + "\" CONTENT=\"True\">\r\n"); } result = true; } String charset = Page.Response.Charset; if (Device.RequiresContentTypeMetaTag && charset != null && charset.Length > 0) { if (writer != null) { writer.Write(String.Format(CultureInfo.InvariantCulture, _contentTypeMetaTag, Device.PreferredRenderingMime, charset)); } result = true; } Form form = this.Control as Form; if (writer == null) { if ((form != null) && (form.Script != null)) { result = true; } } else if ((form != null) && (form.Script != null)) { foreach (Control childControl in form.Script.Controls) { LiteralControl lc = childControl as LiteralControl; if (lc != null) { writer.Write(lc.Text); } else { DataBoundLiteralControl dlc = childControl as DataBoundLiteralControl; if (dlc != null) { writer.Write(dlc.Text); } } } result = true; } return(result); }
public void dgNote_Delete(object sender, DataGridCommandEventArgs e) { DataBoundLiteralControl lb = (DataBoundLiteralControl)e.Item.Cells[0].Controls[3].Controls[0]; PromotionRequest promotion = new PromotionRequest(Convert.ToInt32(lb.Text)); promotion.Delete(); dgNote_ReBind(null, null); }
public void InnerText() { HtmlButton c = new HtmlButton(); DataBoundLiteralControl db = new DataBoundLiteralControl(1, 0); db.SetStaticString(0, "FFF"); c.Controls.Add(db); Assert.AreEqual("FFF", c.InnerText); }
private void get_excel() { DataTable datos = new DataTable(); //(DataTable)GridView_Confirming.DataSource; string pr = _Sql; string pr2 = _sql2; for (int i = 3; i < GridView_Confirming.Columns.Count; i++) { datos.Columns.Add(GridView_Confirming.Columns[i].ToString()); } foreach (GridViewRow row in GridView_Confirming.Rows) { DataRow dr = datos.NewRow(); for (int j = 3; j < GridView_Confirming.Columns.Count; j++) { if (String.IsNullOrEmpty(row.Cells[j].Text)) { if (row.Cells[j].Controls[0].GetType().ToString().Contains("DataBoundLiteralControl")) { DataBoundLiteralControl dat = (DataBoundLiteralControl)row.Cells[j].Controls[0]; dr[GridView_Confirming.Columns[j].ToString()] = dat.Text.Replace("\r\n", "").Trim(); // row.Cells[j].Text; // string a=LB.Text ; } } else if (!row.Cells[j].Text.Equals(" ")) { dr[GridView_Confirming.Columns[j].ToString()] = row.Cells[j].Text; } } datos.Rows.Add(dr); } if (datos.Rows.Count > 0) { using (ExcelPackage pck = new ExcelPackage()) { ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Datos"); List <string> dateColumns = new List <string>() { "F. Emision", "F. Pago", "F. Vencimiento" }; ws.Cells["A1"].LoadFromDataTable(datos, true, OfficeOpenXml.Table.TableStyles.Medium14); FormatWorksheetData(dateColumns, datos, ws); // make sure it is sent as a XLSX file Response.ContentType = "application/vnd.ms-excel"; // make sure it is downloaded rather than viewed in the browser window Response.AddHeader("Content-disposition", "attachment; filename=Confirming.xlsx"); Response.BinaryWrite(pck.GetAsByteArray()); Response.End(); } } }
private static void WriteCSVContentLine(GridViewRow row, TextWriter writer, List <int> skipIndexes, List <int> templateIndexes) { for (int i = 0; i < row.Cells.Count; i++) { if (skipIndexes.Contains(i)) { continue; } string text = "\t"; if (templateIndexes.Contains(i)) { foreach (Control con in row.Cells[i].Controls) { if (con is HyperLink) { // hyperlink text = ((HyperLink)con).Text.Trim(); text = StringUtil.GetDelimitedReadyString(text.Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n").Replace("<br/>", "\\n").Replace("<br />", "\\n"), '\t'); break; } if (con is Label) { text = StringUtil.GetDelimitedReadyString(((Label)con).Text.Trim().Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n").Replace("<br/>", "\\n").Replace("<br />", "\\n"), '\t'); break; } if (con is DataBoundLiteralControl) { // asp:TemplateField DataBoundLiteralControl con1 = (DataBoundLiteralControl)con; text = con1.Text.Trim().Trim('\r', '\n'); MatchCollection mc = LinkParser.Matches(text); if (mc.Count > 0) { text = mc[0].Groups["text"].Value; } text = StringUtil.GetDelimitedReadyString(text.Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n").Replace("<br/>", "\\n").Replace("<br />", "\\n"), '\t'); break; } } } else { text = StringUtil.GetDelimitedReadyString(row.Cells[i].Text.Trim().Trim('\r', '\n').Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n").Replace("<br/>", "\\n").Replace("<br />", "\\n"), '\t'); } if (!string.IsNullOrEmpty(text) && text != "\t") { text = HttpUtility.HtmlDecode(text); } writer.Write(text); } writer.WriteLine(); }
protected override void Render(HtmlTextWriter output) { // Checks if a DataBoundLiteralControl object is present. if ((HasControls()) && (Controls[0] is DataBoundLiteralControl)) { // Obtains the DataBoundLiteralControl instance. DataBoundLiteralControl boundLiteralControl = (DataBoundLiteralControl)Controls[0]; // Retrieves the text in the boundLiteralControl object. String text = boundLiteralControl.Text; output.Write("<h4>Your Message: " + text + "</h4>"); } }
// ********************************************************************* // // BeginBuildTemplate // /// <summary> /// This function creates a new DataBoundLiteralControl and populates /// the Static Strings. Additionally, the DataBinding event handler is /// wired up to a local event handler. Note that there are two BuildItemTemplate /// functions: BeginBuildItemTemplate and FinishBuildItemTemplate. This /// one, begin, is responsible for constructing the code BEFORE the ImageButtons. /// </summary> /// <returns></returns> // // ********************************************************************/ private Control BeginBuildItemTemplate() { // Create a new DataBoundLiteralControl with 8 literal items and 7 databound items dataBoundLiteralControl = new DataBoundLiteralControl(1, 1); // we really don't want to add any static strings, but we need to in order to have the // databound string we wish to emit to appear. Blah. dataBoundLiteralControl.SetStaticString(0, "\n"); // wire up the handleDataBinding event handler to the DataBinding event dataBoundLiteralControl.DataBinding += new System.EventHandler(BeginDataBinding); // return the DataBoundLiteralControl return(dataBoundLiteralControl); }
// ********************************************************************* // // FinishBuildItemTemplate // /// <summary> /// This function creates a new DataBoundLiteralControl and populates /// the Static Strings. Additionally, the DataBinding event handler is /// wired up to a local event handler. Note that there are two BuildItemTemplate /// functions: BeginBuildItemTemplate and FinishBuildItemTemplate. This /// one, finish, is responsible for constructing the code AFTER the ImageButtons. /// </summary> /// <returns></returns> // // ********************************************************************/ private Control FinishBuildItemTemplate() { // Create a new DataBoundLiteralControl with literal items and databound items dataBoundLiteralControl = new DataBoundLiteralControl(6, 5); dataBoundLiteralControl.SetStaticString(0, "<a class=\"postSubject\" href=\"" + Globals.UrlShowPost); dataBoundLiteralControl.SetStaticString(1, "\" target=\"" + FrameToOpenPosts + "\">"); // show the username, if needed if (ShowUsername) { // we are showing the username dataBoundLiteralControl.SetStaticString(2, "</a>\n<span class=\"postText\">from </span><a class=\"postUsername\" href=\"" + Globals.UrlUserProfile); dataBoundLiteralControl.SetStaticString(3, "\">"); if (ShowDatePosted) { // we are showing the username AND the date posted dataBoundLiteralControl.SetStaticString(4, "</a><span class=\"postText\">, posted </span><span class=\"postDate\">"); dataBoundLiteralControl.SetStaticString(5, "</span>\n"); } else { // we are showing just the username dataBoundLiteralControl.SetStaticString(4, "</a>"); } } else if (ShowDatePosted) { // we are showing just the date posted dataBoundLiteralControl.SetStaticString(2, "</a><span class=\"postText\">, posted </span><span class=\"postDate\">"); dataBoundLiteralControl.SetStaticString(3, "</span>\n"); } else if (!ShowUsername && !this.ShowDatePosted) { // we are showing neither the username nor the date posted dataBoundLiteralControl.SetStaticString(2, "</a>\n"); } // wire up the handleDataBinding event handler to the DataBinding event dataBoundLiteralControl.DataBinding += new System.EventHandler(FinishDataBinding); // return the DataBoundLiteralControl return(dataBoundLiteralControl); }
public void GridEditHandler(Object sender, GridViewEditEventArgs e) { GridViewRow row = ChargeDetailGrid.Rows[e.NewEditIndex]; HiddenGERID.Value = row.Cells[10].Text; DataBoundLiteralControl POLUpdLiteral = (DataBoundLiteralControl)row.Cells[3].Controls[0]; POLUpd.SelectedValue = POLUpdLiteral.Text.Trim(); DataBoundLiteralControl ReceiptTypeLiteral = (DataBoundLiteralControl)row.Cells[2].Controls[0]; ReceiptTypeUpd.SelectedValue = ReceiptTypeLiteral.Text.Trim(); //BranchUpd.SelectedValue = row.Cells[0].Text; DataBoundLiteralControl BranchUpdLiteral = (DataBoundLiteralControl)row.Cells[1].Controls[0]; BranchUpd.SelectedValue = BranchUpdLiteral.Text.Trim(); DataBoundLiteralControl ChargeTypeLiteral = (DataBoundLiteralControl)row.Cells[4].Controls[0]; ChargeTypeUpd.SelectedValue = ChargeTypeLiteral.Text.Trim(); DataBoundLiteralControl AdderUpdLiteral = (DataBoundLiteralControl)row.Cells[5].Controls[0]; AdderUpd.Text = AdderUpdLiteral.Text.Trim(); DataBoundLiteralControl MinUpdLiteral = (DataBoundLiteralControl)row.Cells[6].Controls[0]; MinUpd.Text = MinUpdLiteral.Text.Trim(); DataBoundLiteralControl MaxUpdLiteral = (DataBoundLiteralControl)row.Cells[7].Controls[0]; MaxUpd.Text = MaxUpdLiteral.Text.Trim(); DataBoundLiteralControl AdderFuncLiteral = (DataBoundLiteralControl)row.Cells[8].Controls[0]; AdderFuncUpd.SelectedValue = AdderFuncLiteral.Text.Trim(); DataBoundLiteralControl AdderTypeLiteral = (DataBoundLiteralControl)row.Cells[9].Controls[0]; AdderTypeUpd.SelectedValue = AdderTypeLiteral.Text.Trim(); UpdFunction.Value = "Upd"; PageFunc.Value = "Upd"; UpdPanel.Visible = true; DetailPanel.Height = 300; //ChargeDetailGrid.EditIndex = e.NewEditIndex; //ChargeDetailGrid.DataBind(); }
protected internal virtual void RenderExtraCardElements(WmlMobileTextWriter writer) { Form form = this.Control as Form; if ((form != null) && (form.Script != null)) { foreach (Control childControl in form.Script.Controls) { LiteralControl lc = childControl as LiteralControl; if (lc != null) { writer.Write(lc.Text); } else { DataBoundLiteralControl dlc = childControl as DataBoundLiteralControl; if (dlc != null) { writer.Write(dlc.Text); } } } } }
protected void lnkBtnRelatorio_Click(object sender, EventArgs e) { try { int noOfColumns = 0, noOfRows = 0; DataTable tbl = null; if (grid.AutoGenerateColumns) { tbl = grid.DataSource as DataTable; // Gets the DataSource of the GridView Control. noOfColumns = tbl.Columns.Count; noOfRows = tbl.Rows.Count; } else { noOfColumns = grid.Columns.Count - 2; noOfRows = grid.Rows.Count; } float HeaderTextSize = 8; float ReportNameSize = 10; float ReportTextSize = 8; float ApplicationNameSize = 7; // Creates a PDF document Document document = null; document = new Document(PageSize.A4, 0, 0, 15, 5); // Creates a PdfPTable with column count of the table equal to no of columns of the gridview or gridview datasource. iTextSharp.text.pdf.PdfPTable mainTable = new iTextSharp.text.pdf.PdfPTable(noOfColumns); // Sets the first 4 rows of the table as the header rows which will be repeated in all the pages. mainTable.HeaderRows = 4; // Creates a PdfPTable with 2 columns to hold the header in the exported PDF. iTextSharp.text.pdf.PdfPTable headerTable = new iTextSharp.text.pdf.PdfPTable(2); // Creates a phrase to hold the application name at the left hand side of the header. Phrase phApplicationName = new Phrase("Cadastro dos Funcionarios", FontFactory.GetFont("Arial", ApplicationNameSize, iTextSharp.text.Font.NORMAL)); // Creates a PdfPCell which accepts a phrase as a parameter. PdfPCell clApplicationName = new PdfPCell(phApplicationName); // Sets the border of the cell to zero. clApplicationName.Border = PdfPCell.NO_BORDER; // Sets the Horizontal Alignment of the PdfPCell to left. clApplicationName.HorizontalAlignment = Element.ALIGN_LEFT; // Creates a phrase to show the current date at the right hand side of the header. Phrase phDate = new Phrase(DateTime.Now.Date.ToString("dd/MM/yyyy"), FontFactory.GetFont("Arial", ApplicationNameSize, iTextSharp.text.Font.NORMAL)); // Creates a PdfPCell which accepts the date phrase as a parameter. PdfPCell clDate = new PdfPCell(phDate); // Sets the Horizontal Alignment of the PdfPCell to right. clDate.HorizontalAlignment = Element.ALIGN_RIGHT; // Sets the border of the cell to zero. clDate.Border = PdfPCell.NO_BORDER; // Adds the cell which holds the application name to the headerTable. headerTable.AddCell(clApplicationName); // Adds the cell which holds the date to the headerTable. headerTable.AddCell(clDate); // Sets the border of the headerTable to zero. headerTable.DefaultCell.Border = PdfPCell.NO_BORDER; // Creates a PdfPCell that accepts the headerTable as a parameter and then adds that cell to the main PdfPTable. PdfPCell cellHeader = new PdfPCell(headerTable); cellHeader.Border = PdfPCell.NO_BORDER; // Sets the column span of the header cell to noOfColumns. cellHeader.Colspan = noOfColumns; // Adds the above header cell to the table. mainTable.AddCell(cellHeader); // Creates a phrase which holds the file name. Phrase phHeader = new Phrase("Funcionarios Cadastrados", FontFactory.GetFont("Arial", ReportNameSize, iTextSharp.text.Font.BOLD)); PdfPCell clHeader = new PdfPCell(phHeader); clHeader.Colspan = noOfColumns; clHeader.Border = PdfPCell.NO_BORDER; clHeader.HorizontalAlignment = Element.ALIGN_CENTER; mainTable.AddCell(clHeader); // Creates a phrase for a new line. Phrase phSpace = new Phrase("\n"); PdfPCell clSpace = new PdfPCell(phSpace); clSpace.Border = PdfPCell.NO_BORDER; clSpace.Colspan = noOfColumns; mainTable.AddCell(clSpace); // Sets the gridview column names as table headers. for (int i = 0; i < noOfColumns; i++) { Phrase ph = null; if (grid.AutoGenerateColumns) { ph = new Phrase(tbl.Columns[i].ColumnName, FontFactory.GetFont("Arial", HeaderTextSize, iTextSharp.text.Font.BOLD)); } else { ph = new Phrase(grid.Columns[i].HeaderText, FontFactory.GetFont("Arial", HeaderTextSize, iTextSharp.text.Font.BOLD)); } mainTable.AddCell(ph); } // Reads the gridview rows and adds them to the mainTable for (int rowNo = 0; rowNo < noOfRows; rowNo++) { for (int columnNo = 0; columnNo < noOfColumns; columnNo++) { if (grid.AutoGenerateColumns) { string s = grid.Rows[rowNo].Cells[columnNo].Text.Trim(); if (s.Equals(" ")) { s = ""; } Phrase ph = new Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL)); mainTable.AddCell(ph); } else { if (grid.Columns[columnNo] is TemplateField) { DataBoundLiteralControl lc = grid.Rows[rowNo].Cells[columnNo].Controls[0] as DataBoundLiteralControl; string s = lc.Text.Trim(); if (s.Equals(" ")) { s = ""; } Phrase ph = new Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL)); mainTable.AddCell(ph); } else { string s = grid.Rows[rowNo].Cells[columnNo].Text.Trim(); if (s.Equals(" ")) { s = ""; } Phrase ph = new Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL)); mainTable.AddCell(ph); } } } // Tells the mainTable to complete the row even if any cell is left incomplete. mainTable.CompleteRow(); } // Gets the instance of the document created and writes it to the output stream of the Response object. PdfWriter.GetInstance(document, Response.OutputStream); //// Creates a footer for the PDF document. //HeaderFooter pdfFooter = new HeaderFooter(new Phrase(), true); //pdfFooter.Alignment = Element.ALIGN_CENTER; //pdfFooter.Border = iTextSharp.text.Rectangle.NO_BORDER; //// Sets the document footer to pdfFooter. //document.Footer = pdfFooter; // Opens the document. document.Open(); // Adds the mainTable to the document. document.Add(mainTable); // Closes the document. document.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment; filename=Relatorio de Funcionarios de " + DateTime.Now.ToLongDateString() + ".pdf"); Response.End(); } catch { } }
protected void btnUnificar_Click(object sender, EventArgs e) { if (validarSeleccion()) { RadioButton rb = new RadioButton(); CheckBox ch = new CheckBox(); string codCorrecto = ""; ArrayList sqlStrings = new ArrayList(); foreach (DataGridItem i in operaciones.Items) { rb = (RadioButton)i.FindControl("rbsira"); if (rb.Checked == true) { DataBoundLiteralControl tx = (DataBoundLiteralControl)i.Cells[0].Controls[0]; codCorrecto = tx.Text.Trim(); } } foreach (DataGridItem i in operaciones.Items) { // Se puede mejorar la velocidad creando una tabla temporal cargandole los codigo errados y reemplazando la sentencias = '" + codErroneo + "' por in (select ptem_operacion from tablatemporal); string codErroneo = ""; ch = (CheckBox)i.FindControl("chkErrada"); if (ch.Checked == true) { DataBoundLiteralControl tx = (DataBoundLiteralControl)i.Cells[0].Controls[0]; codErroneo = tx.Text.Trim(); //string operacion = DBFunctions.SingleData(""); //string opAnulacion = DBFunctions.SingleData(""); sqlStrings.Add( "MERGE INTO dbxschema.dordenoperacion ar " + "USING (SELECT PDOC_CODIGO, MORD_NUMEORDE, PTEM_OPERACION FROM dbxschema.dordenoperacion) ac " + "ON (ar.PDOC_CODIGO = ac.PDOC_CODIGO AND ar.MORD_NUMEORDE = ac.MORD_NUMEORDE and ac.ptem_operacion = '" + codCorrecto + "') " + "WHEN MATCHED and ar.ptem_operacion = '" + codErroneo + "' " + "THEN delete; " ); sqlStrings.Add("UPDATE dbxschema.dordenoperacion SET ptem_operacion = '" + codCorrecto + "' WHERE PTEM_OPERACION='" + codErroneo + "';"); sqlStrings.Add( "MERGE INTO dbxschema.dordenoperacionANULACION ar " + "USING (SELECT PDOC_CODIGO, MORD_NUMEORDE, PTEM_OPERACION FROM dbxschema.dordenoperacionANULACION) ac " + "ON (ar.PDOC_CODIGO = ac.PDOC_CODIGO AND ar.MORD_NUMEORDE = ac.MORD_NUMEORDE and ac.ptem_operacion = '" + codCorrecto + "' and ar.ptem_operacion = '" + codErroneo + "') " + "WHEN MATCHED and ar.ptem_operacion = '" + codErroneo + "' " + "THEN delete; " ); sqlStrings.Add( "UPDATE dbxschema.dordenoperacionanulacion SET ptem_operacion = '" + codCorrecto + "' WHERE ptem_operacion='" + codErroneo + "';"); sqlStrings.Add( "MERGE INTO dbxschema.dobservacionesOT ar " + "USING (SELECT PDOC_CODIGO, MORD_NUMEORDE, PTEM_OPERACION FROM dbxschema.dobservacionesOT) ac " + "ON (ar.PDOC_CODIGO = ac.PDOC_CODIGO AND ar.MORD_NUMEORDE = ac.MORD_NUMEORDE and ac.ptem_operacion = '" + codCorrecto + "') " + "WHEN MATCHED and ar.ptem_operacion = '" + codErroneo + "' " + "THEN delete; " ); sqlStrings.Add("UPDATE dbxschema.dobservacionesOT SET ptem_operacion = '" + codCorrecto + "' WHERE PTEM_OPERACION='" + codErroneo + "';"); sqlStrings.Add( "MERGE INTO dbxschema.ptiempotaller ar " + "USING (SELECT ptie_grupcata, ptie_tempario FROM dbxschema.ptiempotaller) ac " + "ON (ar.ptie_grupcata = ac.ptie_grupcata and ac.ptie_tempario = '" + codCorrecto + "') " + "WHEN MATCHED and ar.ptie_tempario = '" + codErroneo + "' " + "THEN delete; " ); sqlStrings.Add( "UPDATE dbxschema.ptiempotaller SET ptie_tempario = '" + codCorrecto + "' WHERE ptie_tempario='" + codErroneo + "';"); sqlStrings.Add( "MERGE INTO dbxschema.mkitoperacion ar " + "USING (SELECT mkit_codikitoper, mkit_operacion FROM dbxschema.mkitoperacion) ac " + "ON (ar.mkit_codikitoper = ac.mkit_codikitoper and ac.mkit_operacion = '" + codCorrecto + "') " + "WHEN MATCHED and ar.mkit_operacion = '" + codErroneo + "' " + "THEN delete; " ); sqlStrings.Add( "UPDATE dbxschema.mkitoperacion SET mkit_operacion = '" + codCorrecto + "' WHERE mkit_operacion='" + codErroneo + "';"); sqlStrings.Add( "DELETE FROM dbxschema.ptempario WHERE ptem_operacion = '" + codErroneo + "';"); sqlStrings.Add("COMMIT;"); } } if (DBFunctions.Transaction(sqlStrings)) { Response.Redirect(ConfigurationManager.AppSettings["MainIndexPage"] + "?process=Automotriz.UnificarTemparioOperaciones&OK=1"); } else { Utils.MostrarAlerta(Response, "Error durante la unificación! Revisar registros."); } } else { Utils.MostrarAlerta(Response, "Para realizar la unificación debe seleccionar una operación correcta y una o más operaciones erradas!"); } }
public void GetPDFValue(TestRequestClass aTestRequestClass) { int noOfColumns = 0, noOfRows = 0; DataTable tbl = null; if (showGridView.AutoGenerateColumns) { tbl = showGridView.DataSource as DataTable; // Gets the DataSource of the GridView Control. noOfColumns = tbl.Columns.Count; noOfRows = tbl.Rows.Count; } else { noOfColumns = showGridView.Columns.Count; noOfRows = showGridView.Rows.Count; } float HeaderTextSize = 8; float ReportNameSize = 10; float ReportTextSize = 8; float ApplicationNameSize = 12; Document document = null; if (LandScape == true) { document = new Document(PageSize.A4.Rotate(), 0, 0, 15, 5); } else { document = new Document(PageSize.A4, 0, 0, 15, 5); } iTextSharp.text.pdf.PdfPTable mainTable = new iTextSharp.text.pdf.PdfPTable(noOfColumns); mainTable.HeaderRows = 5; iTextSharp.text.pdf.PdfPTable headerTable = new iTextSharp.text.pdf.PdfPTable(2); Phrase phApplicationName = new Phrase( "Bill No:" + aTestRequestClass.BillNo + "\nName: " + aTestRequestClass.Name + "\nMobile No: " + aTestRequestClass.MobileNo + "\nDate Of Birth: " + aTestRequestClass.DateofBirth + " ", FontFactory.GetFont("Arial", ApplicationNameSize, iTextSharp.text.Font.BOLD)); PdfPCell clApplicationName = new PdfPCell(phApplicationName); clApplicationName.Border = PdfPCell.NO_BORDER; clApplicationName.HorizontalAlignment = Element.ALIGN_LEFT; Phrase aphSpace = new Phrase("\n"); PdfPCell aclSpace = new PdfPCell(aphSpace); aclSpace.Border = PdfPCell.NO_BORDER; aclSpace.Colspan = noOfColumns; mainTable.AddCell(aclSpace); Phrase phDate = new Phrase("Entry Date: " + DateTime.Now.Date.ToString("dd/MM/yyyy"), FontFactory.GetFont("Arial", ApplicationNameSize, iTextSharp.text.Font.NORMAL)); PdfPCell clDate = new PdfPCell(phDate); clDate.HorizontalAlignment = Element.ALIGN_RIGHT; clDate.Border = PdfPCell.NO_BORDER; headerTable.AddCell(clApplicationName); headerTable.AddCell(clDate); headerTable.DefaultCell.Border = PdfPCell.NO_BORDER; Phrase phHeader = new Phrase("PATIENT BILL ", FontFactory.GetFont("Arial", ReportNameSize, iTextSharp.text.Font.BOLD)); PdfPCell clHeader = new PdfPCell(phHeader); clHeader.Colspan = noOfColumns; clHeader.Border = PdfPCell.NO_BORDER; clHeader.HorizontalAlignment = Element.ALIGN_CENTER; mainTable.AddCell(clHeader); PdfPCell cellHeader = new PdfPCell(headerTable); cellHeader.Border = PdfPCell.NO_BORDER; cellHeader.Colspan = noOfColumns; mainTable.AddCell(cellHeader); Phrase phSpace = new Phrase("\n"); PdfPCell clSpace = new PdfPCell(phSpace); clSpace.Border = PdfPCell.NO_BORDER; clSpace.Colspan = noOfColumns; mainTable.AddCell(clSpace); for (int i = 0; i < noOfColumns; i++) { Phrase ph = null; if (showGridView.AutoGenerateColumns) { ph = new Phrase(tbl.Columns[i].ColumnName, FontFactory.GetFont("Arial", HeaderTextSize, iTextSharp.text.Font.BOLD)); } else { ph = new Phrase(showGridView.Columns[i].HeaderText, FontFactory.GetFont("Arial", HeaderTextSize, iTextSharp.text.Font.BOLD)); } mainTable.AddCell(ph); } for (int rowNo = 0; rowNo < noOfRows; rowNo++) { for (int columnNo = 0; columnNo < noOfColumns; columnNo++) { if (showGridView.AutoGenerateColumns) { string s = showGridView.Rows[rowNo].Cells[columnNo].Text.Trim(); Phrase ph = new Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL)); mainTable.AddCell(ph); } else { if (showGridView.Columns[columnNo] is TemplateField) { DataBoundLiteralControl lc = showGridView.Rows[rowNo].Cells[columnNo].Controls[0] as DataBoundLiteralControl; string s = lc.Text.Trim(); Phrase ph = new Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL)); mainTable.AddCell(ph); } else { string s = showGridView.Rows[rowNo].Cells[columnNo].Text.Trim(); Phrase ph = new Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL)); mainTable.AddCell(ph); } } } mainTable.CompleteRow(); } Phrase phHeaderTotal = new Phrase("Total: " + aTestRequestClass.TotalFee + " TK ", FontFactory.GetFont("Arial", ReportNameSize, iTextSharp.text.Font.BOLD)); PdfPCell clHeaderTotal = new PdfPCell(phHeaderTotal); clHeaderTotal.Colspan = noOfColumns; clHeaderTotal.Border = PdfPCell.BOX; clHeaderTotal.HorizontalAlignment = Element.ALIGN_RIGHT; mainTable.AddCell(clHeaderTotal); PdfWriter.GetInstance(document, Response.OutputStream); document.Open(); document.Add(mainTable); document.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment; filename= PatientBill.pdf"); Response.End(); }
private void ExportToPDF(GridView gvReport, string tenBang, bool LandScape) { int noOfColumns = 0, noOfRows = 0; DataTable tbl = null; if (gvReport.AutoGenerateColumns) { tbl = gvReport.DataSource as DataTable; // Gets the DataSource of the GridView Control. noOfColumns = tbl.Columns.Count; noOfRows = tbl.Rows.Count; } else { noOfColumns = gvReport.Columns.Count; noOfRows = gvReport.Rows.Count; } float ApplicationNameSize = 7; // Creates a PDF document Document document = null; if (LandScape == true) { // Sets the document to A4 size and rotates it so that the orientation of the page is Landscape. document = new Document(PageSize.A4.Rotate(), 0, 0, 15, 5); } else { document = new Document(PageSize.A4, 0, 0, 15, 5); } // Creates a PdfPTable with column count of the table equal to no of columns of the gridview or gridview datasource. iTextSharp.text.pdf.PdfPTable mainTable = new iTextSharp.text.pdf.PdfPTable(noOfColumns); // Sets the first 4 rows of the table as the header rows which will be repeated in all the pages. mainTable.HeaderRows = 4; string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "times.TTF"); BaseFont bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font text = new iTextSharp.text.Font(bf, 14, iTextSharp.text.Font.NORMAL); // Creates a PdfPTable with 2 columns to hold the header in the exported PDF. iTextSharp.text.pdf.PdfPTable headerTable = new iTextSharp.text.pdf.PdfPTable(2); // Creates a phrase to hold the application name at the left hand side of the header. Phrase phApplicationName = new Phrase("Nhom 5 - Library management", text); // Creates a PdfPCell which accepts a phrase as a parameter. PdfPCell clApplicationName = new PdfPCell(phApplicationName); // Sets the border of the cell to zero. clApplicationName.Border = PdfPCell.NO_BORDER; // Sets the Horizontal Alignment of the PdfPCell to left. clApplicationName.HorizontalAlignment = Element.ALIGN_LEFT; // Creates a phrase to show the current date at the right hand side of the header. Phrase phDate = new Phrase(DateTime.Now.Date.ToString("dd/MM/yyyy"), FontFactory.GetFont("Arial", ApplicationNameSize, iTextSharp.text.Font.NORMAL)); // Creates a PdfPCell which accepts the date phrase as a parameter. PdfPCell clDate = new PdfPCell(phDate); // Sets the Horizontal Alignment of the PdfPCell to right. clDate.HorizontalAlignment = Element.ALIGN_RIGHT; // Sets the border of the cell to zero. clDate.Border = PdfPCell.NO_BORDER; // Adds the cell which holds the application name to the headerTable. headerTable.AddCell(clApplicationName); // Adds the cell which holds the date to the headerTable. headerTable.AddCell(clDate); // Sets the border of the headerTable to zero. headerTable.DefaultCell.Border = PdfPCell.NO_BORDER; // Creates a PdfPCell that accepts the headerTable as a parameter and then adds that cell to the main PdfPTable. PdfPCell cellHeader = new PdfPCell(headerTable); cellHeader.Border = PdfPCell.NO_BORDER; // Sets the column span of the header cell to noOfColumns. cellHeader.Colspan = noOfColumns; // Adds the above header cell to the table. mainTable.AddCell(cellHeader); // Creates a phrase which holds the file name. Phrase phHeader = new Phrase(tenBang, text); PdfPCell clHeader = new PdfPCell(phHeader); clHeader.Colspan = noOfColumns; clHeader.Border = PdfPCell.NO_BORDER; clHeader.HorizontalAlignment = Element.ALIGN_CENTER; mainTable.AddCell(clHeader); // Creates a phrase for a new line. Phrase phSpace = new Phrase("\n"); PdfPCell clSpace = new PdfPCell(phSpace); clSpace.Border = PdfPCell.NO_BORDER; clSpace.Colspan = noOfColumns; mainTable.AddCell(clSpace); // Sets the gridview column names as table headers. for (int i = 0; i < noOfColumns; i++) { Phrase ph = null; if (gvReport.AutoGenerateColumns) { ph = new Phrase(tbl.Columns[i].ColumnName, text); } else { ph = new Phrase(gvReport.Columns[i].HeaderText, text); } mainTable.AddCell(ph); } // Reads the gridview rows and adds them to the mainTable for (int rowNo = 0; rowNo < noOfRows; rowNo++) { for (int columnNo = 0; columnNo < noOfColumns; columnNo++) { if (gvReport.AutoGenerateColumns) { string s = gvReport.Rows[rowNo].Cells[columnNo].Text.Trim(); Phrase ph = new Phrase(s, text); mainTable.AddCell(ph); } else { if (gvReport.Columns[columnNo] is TemplateField) { DataBoundLiteralControl lc = gvReport.Rows[rowNo].Cells[columnNo].Controls[0] as DataBoundLiteralControl; string s = lc.Text.Trim(); Phrase ph = new Phrase(s, text); mainTable.AddCell(ph); } else { string s = gvReport.Rows[rowNo].Cells[columnNo].Text.Trim(); Phrase ph = new Phrase(s, text); mainTable.AddCell(ph); } } } // Tells the mainTable to complete the row even if any cell is left incomplete. mainTable.CompleteRow(); } // Gets the instance of the document created and writes it to the output stream of the Response object. PdfWriter.GetInstance(document, Response.OutputStream); // Creates a footer for the PDF document. //HeaderFooter pdfFooter = new HeaderFooter(new Phrase(), true); //pdfFooter.Alignment = Element.ALIGN_CENTER; //pdfFooter.Border = Rectangle.NO_BORDER; //// Sets the document footer to pdfFooter. //document.Footer = pdfFooter; // Opens the document. document.Open(); // Adds the mainTable to the document. document.Add(mainTable); // Closes the document. document.Close(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment; filename= SampleExport.pdf"); Response.End(); }
public void ExportToPDF(string ReportName, GridView grdPDF, bool isLandscape, string Filename) { int noOfColumns = 0, noOfRows = 0; DataTable tbl = null; if (grdPDF.AutoGenerateColumns) { tbl = grdPDF.DataSource as DataTable; // Gets the DataSource of the GridView Control. noOfColumns = tbl.Columns.Count; noOfRows = tbl.Rows.Count; } else { noOfColumns = grdPDF.Columns.Count; noOfRows = grdPDF.Rows.Count; } float HeaderTextSize = 8; float ReportNameSize = 10; float ReportTextSize = 8; float ApplicationNameSize = 7; // Creates a PDF document Document document = null; if (isLandscape == true) { // Sets the document to A4 size and rotates it so that the orientation of the page is Landscape. document = new Document(PageSize.A4.Rotate(), 0, 0, 15, 5); } else { document = new Document(PageSize.A4, 0, 0, 15, 5); } PdfPTable mainTable = new iTextSharp.text.pdf.PdfPTable(noOfColumns); // Sets the first 4 rows of the table as the header rows which will be repeated in all the pages. mainTable.HeaderRows = 4; // Creates a PdfPTable with 2 columns to hold the header in the exported PDF. PdfPTable headerTable = new iTextSharp.text.pdf.PdfPTable(2); //iTextSharp.text.Image imgLogo = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("../Images/medtech_logo.jpg")); //imgLogo.ScaleToFit(100, 25); //PdfPCell clApplicationName = new PdfPCell(imgLogo); //clApplicationName.Border = PdfPCell.NO_BORDER; //clApplicationName.HorizontalAlignment = Element.ALIGN_LEFT; // Creates a phrase to show the current date at the right hand side of the header. Phrase phDate = new Phrase(DateTime.Now.Date.ToString("dd-MMM-yyyy"), FontFactory.GetFont("Arial", ApplicationNameSize, iTextSharp.text.Font.NORMAL)); // Creates a PdfPCell which accepts the date phrase as a parameter. PdfPCell clDate = new PdfPCell(phDate); // Sets the Horizontal Alignment of the PdfPCell to right. clDate.HorizontalAlignment = Element.ALIGN_RIGHT; // Sets the border of the cell to zero. clDate.Border = PdfPCell.NO_BORDER; //headerTable.AddCell(clApplicationName); headerTable.AddCell(clDate); headerTable.DefaultCell.Border = PdfPCell.NO_BORDER; // Creates a PdfPCell that accepts the headerTable as a parameter and then adds that cell to the main PdfPTable. PdfPCell cellHeader = new PdfPCell(headerTable); cellHeader.Border = PdfPCell.NO_BORDER; // Sets the column span of the header cell to noOfColumns. cellHeader.Colspan = noOfColumns; // Adds the above header cell to the table. mainTable.AddCell(cellHeader); // Creates a phrase which holds the file name. //Phrase phHeader = new Phrase(sApplicationName, FontFactory.GetFont("Arial", ReportNameSize, iTextSharp.text.Font.BOLD)); //PdfPCell clHeader = new PdfPCell(phHeader); //clHeader.Colspan = noOfColumns; //clHeader.Border = PdfPCell.NO_BORDER; //clHeader.HorizontalAlignment = Element.ALIGN_CENTER; //mainTable.AddCell(clHeader); // Creates a phrase for a new line. Phrase phSpace = new Phrase("\n"); PdfPCell clSpace = new PdfPCell(phSpace); clSpace.Border = PdfPCell.NO_BORDER; clSpace.Colspan = noOfColumns; mainTable.AddCell(clSpace); // Sets the gridview column names as table headers. for (int i = 0; i < noOfColumns; i++) { Phrase ph = null; if (grdPDF.AutoGenerateColumns) { ph = new Phrase(tbl.Columns[i].ColumnName, FontFactory.GetFont("Arial", HeaderTextSize, iTextSharp.text.Font.BOLD)); } else { ph = new Phrase(grdPDF.Columns[i].HeaderText, FontFactory.GetFont("Arial", HeaderTextSize, iTextSharp.text.Font.BOLD)); } mainTable.AddCell(ph); } // Reads the gridview rows and adds them to the mainTable for (int rowNo = 0; rowNo < noOfRows; rowNo++) { for (int columnNo = 0; columnNo < noOfColumns; columnNo++) { if (grdPDF.AutoGenerateColumns) { string s = grdPDF.Rows[rowNo].Cells[columnNo].Text.Trim(); Phrase ph = new Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL)); mainTable.AddCell(ph); } else { string s = ""; if (grdPDF.Columns[columnNo] is TemplateField) { DataBoundLiteralControl lc = grdPDF.Rows[rowNo].Cells[columnNo].Controls[0] as DataBoundLiteralControl; if (lc != null) { s = lc.Text.Trim(); } else { for (int i = 0; i < grdPDF.Rows[rowNo].Cells[columnNo].Controls.Count; i++) { if (grdPDF.Rows[rowNo].Cells[columnNo].Controls[i].GetType() == typeof(TextBox)) { s = (grdPDF.Rows[rowNo].Cells[columnNo].Controls[i] as TextBox).Text; } else if (grdPDF.Rows[rowNo].Cells[columnNo].Controls[i].GetType() == typeof(Label)) { s = (grdPDF.Rows[rowNo].Cells[columnNo].Controls[i] as Label).Text; } else if (grdPDF.Rows[rowNo].Cells[columnNo].Controls[i].GetType() == typeof(System.Web.UI.WebControls.Image)) { s = (grdPDF.Rows[rowNo].Cells[columnNo].Controls[i] as System.Web.UI.WebControls.Image).ToolTip; } } } Phrase ph = new Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL)); mainTable.AddCell(ph); } else { s = grdPDF.Rows[rowNo].Cells[columnNo].Text.Trim(); Phrase ph = new Phrase(s, FontFactory.GetFont("Arial", ReportTextSize, iTextSharp.text.Font.NORMAL)); mainTable.AddCell(ph); } } } mainTable.CompleteRow(); } PdfWriter.GetInstance(document, HttpContext.Current.Response.OutputStream); //HeaderFooter pdfFooter = new HeaderFooter(new Phrase(), true); //pdfFooter.Alignment = Element.ALIGN_CENTER; //pdfFooter.Border = iTextSharp.text.Rectangle.NO_BORDER; //document.Footer = pdfFooter; document.Open(); document.Add(mainTable); document.Close(); HttpContext.Current.Response.ContentType = "application/pdf"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename= " + Filename + "_" + DateTime.Now.ToString("dd_MMM_yyyy") + ".pdf"); HttpContext.Current.Response.End(); }
private void CreaCuerpoExcel(GridView gridView) { foreach (GridViewRow item in gridView.Rows) { ObtenRango(gridView); CreaEstiloCeldas(ref RangeCells, gridView, item); if (revisaFormatoCaldaXCelda) { CreaEstiloCeldaSingle(ref RangeCells, gridView, item); } int x = 0; int j = 0; foreach (TableCell tCell in item.Cells) { if (!configExcel.LstIndOmitir.Contains(x)) { if (tCell.Controls.Count > 0) { for (int k = 0; k < tCell.Controls.Count; k++) { string Tipo = tCell.Controls[k].GetType().ToString(); switch (Tipo) { case "System.Web.UI.DataBoundLiteralControl": DataBoundLiteralControl objDBLC = (DataBoundLiteralControl)tCell.Controls[k]; cells[headerColumns[x - j] + rowIndex.ToString()].Value = objDBLC.Text.removerAcentos().Replace(" ", ""); break; case "System.Web.UI.WebControls.CheckBox": CheckBox objCheckBox = (CheckBox)tCell.Controls[k]; string strSIoNO = string.Empty; if (objCheckBox.Checked) { strSIoNO = "Si"; } else { strSIoNO = "No"; } cells[headerColumns[x - j] + rowIndex.ToString()].Value = strSIoNO; break; case "System.Web.UI.WebControls.DataControlLinkButton": LinkButton objLinkButton = (LinkButton)tCell.Controls[k]; cells[headerColumns[x - j] + rowIndex.ToString()].Value = objLinkButton.Text.removerAcentos().Replace(" ", ""); break; } } } else { cells[headerColumns[x - j] + rowIndex.ToString()].Value = item.Cells[x].Text.ConvertirAcentosHTML().Replace(" ", "").ConvertirCaracteresHTML(); } } else { j++; } x++; } if (configExcel.ArrDatakeys != null) { foreach (string sllave in configExcel.ArrDatakeys) { string sKey = gridView.DataKeys[Convert.ToInt32(rowIndex) - 2].Values[sllave].ToString(); cells[headerColumns[x - j] + rowIndex.ToString()].Value = sKey.ConvertirAcentosHTML().Replace(" ", ""); x++; } } rowIndex++; } }
private static string getControlText(ControlCollection controls) { string text = "\t"; foreach (Control con in controls) { if (con is System.Web.UI.HtmlControls.HtmlAnchor) { // hyperlink text = ((System.Web.UI.HtmlControls.HtmlAnchor)con).InnerText.Trim(); text = StringUtil.GetDelimitedReadyString(text.Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n").Replace("<br/>", "\\n").Replace("<br />", "\\n"), '\t'); break; } if (con is HyperLink) { // hyperlink text = ((HyperLink)con).Text.Trim(); text = StringUtil.GetDelimitedReadyString(text.Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n").Replace("<br/>", "\\n").Replace("<br />", "\\n"), '\t'); break; } if (con is LinkButton) { var lbtn = con as LinkButton; if (lbtn != null) { if (lbtn.HasControls()) { text = getControlText(lbtn.Controls); text = StringUtil.GetDelimitedReadyString(text.Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n").Replace("<br/>", "\\n").Replace("<br />", "\\n"), '\t'); break; } else { text = StringUtil.GetDelimitedReadyString(lbtn.Text.Trim().Trim('\r', '\n').Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n").Replace("<br/>", "\\n").Replace("<br />", "\\n"), '\t'); break; } } } if (con is Label) { text = StringUtil.GetDelimitedReadyString(((Label)con).Text.Trim().Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n").Replace("<br/>", "\\n").Replace("<br />", "\\n"), '\t'); break; } if (con is TextBox) { text = StringUtil.GetDelimitedReadyString(((TextBox)con).Text.Trim().Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n").Replace("<br/>", "\\n").Replace("<br />", "\\n"), '\t'); break; } if (con is DataBoundLiteralControl) { // asp:TemplateField DataBoundLiteralControl con1 = (DataBoundLiteralControl)con; text = con1.Text.Trim().Trim('\r', '\n'); MatchCollection mc = LinkParser.Matches(text); if (mc.Count > 0) { text = mc[0].Groups["text"].Value; } text = StringUtil.GetDelimitedReadyString(text.Replace(" ", "").Replace(""", "\"").Replace("<br>", "").Replace("<br/>", "").Replace("<br />", ""), ' '); text = text.Replace("\r", "").Replace("\n", "").Replace(" ", "").Replace("\"", ""); //text = // text.Replace(" ", "").Replace(""", "\"").Replace("<br>", "\\n"). // Replace("<br/>", "\\n").Replace("<br />", "\\n"); break; } } return(text); }