Inquiridor
Nçao consigo adicionar css nos componentes criados dinamicamente

Pergunta
-
Ola pessoal, sou relativamente novo em .net.
estou montanto uma folha de pagamento com componentes de tabela dinamicos, como TableCell e TableRow.
preciso adicionar um css nas celulas que crio, porém usando a propriedade CssClass do componente, quando vou imprimir a tabela, as bordas que colocquei no css não aparecem.
Fonte aspx
.BordasSomenteEsquerda { border-left-style: solid; border-left-color: Black; border-left-width: thin; } .BordaSomenteCima { border-top-style: solid; border-top-color: Black; border-top-width: thin; } .BordaSomenteBaixo { border-bottom-style: solid; border-bottom-color: Black; border-bottom-width: thin; } .BordaSomenteDireita { border-bottom-style: solid; border-bottom-color: Black; border-bottom-width: thin; } .BordaSolidTotal { border-style: solid; border-width:thin; border-color: Black; } </style> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <br /> <br /> <asp:Panel ID="pnImprime" runat="server"> <div id ="Tabelas" runat="server" > </div> </asp:Panel> </asp:Content>
Parte do fonte Cs.TableCell tbCell1Cod = new TableCell(); TableCell tbCell2Descricao = new TableCell(); TableCell tbCell3Referencia = new TableCell(); TableCell tbCell4Quantidade = new TableCell(); TableCell tbCell5Vencimentos = new TableCell(); TableCell tbCell6Descontos = new TableCell(); TableRow linha1 = new TableRow(); #region Mesclas tbCell1Cod.ColumnSpan = 0; tbCell2Descricao.ColumnSpan = 2; #endregion #region Bordas da Celula tbCell1Cod.CssClass = "BordaSomenteDireita"; tbCell2Descricao.CssClass = "BordaSomenteDireita"; tbCell3Referencia.CssClass = "BordaSomenteDireita"; tbCell4Quantidade.CssClass = "BordaSomenteDireita"; tbCell5Vencimentos.CssClass = "BordaSomenteDireita"; tbCell6Descontos.CssClass = "BordaSomenteDireita";
Alguem poderia me ajudar?
Todas as Respostas
-
ColenetzTenta utilizar a propridade Attributes ex:
tbCell1Cod.Attributes("class", "BordaSomenteDireita"); tbCell2Descricao.Attributes("class","BordaSomenteDireita"); tbCell3Referencia.Attributes("class", "BordaSomenteDireita"); tbCell4Quantidade.Attributes("class", "BordaSomenteDireita"); tbCell5Vencimentos.Attributes("class","BordaSomenteDireita"); tbCell6Descontos.Attributes( "class", "BordaSomenteDireita");
Espero ter ajudado []'s
-
Vou tentar obrigado e retorno de seu certo.
Ola Marcos,
Fiz o que voce passou e funcionou de certo modo. Na tela do Aspx, aparecem o CSS que coloquei, porém quando aparece a tela de visualização de impressão, as bordas não estão lá.
Segue o que faço para imprimir:
Eu tenho um Panel no aspx e passo pra ele a tabela assim:
pnImprime.Controls.Add(tb1VIA);
Vou enviar o codigo do print helper que achei na net:
public class PrintHelper { public PrintHelper() { // // TODO: Add constructor logic here // } public static void PrintWebControl(Control ctrl) { PrintWebControl(ctrl, string.Empty); } public static void PrintWebControl(Control ctrl, string Script) { StringWriter stringWrite = new StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite); if (ctrl is WebControl) { Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w; } Page pg = new Page(); pg.EnableEventValidation = false; if (Script != string.Empty) { pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script); } HtmlForm frm = new HtmlForm(); pg.Controls.Add(frm); frm.Attributes.Add("runat", "server"); frm.Controls.Add(ctrl); pg.DesignerInitialize(); pg.RenderControl(htmlWrite); string strHTML = stringWrite.ToString(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Write(strHTML); HttpContext.Current.Response.Write("<script>window.print();</script>"); HttpContext.Current.Response.End(); } } }
Se puder me dar mais uma ajuda agradeço.
- Editado Colenetz sexta-feira, 6 de abril de 2012 22:15