Fórum Exportar gridview para excel #3525
11/03/2009
0
Tenho uma pagina com gridview, essa pagina tem um botão com a função de gerar um excel com os dados do gridview. Quero manipular esse gridview para que ele tenha vários cabeçalhos um a cima do outro, não apenas o cabeçalho de cada coluna, mas sim que pegue uma linha inteira (os exemplos em anexo mostram como ele estava e como deve ficar), e esses dados sejam enviados para o excel.
Obrigado
Tiago Leite
Codigo aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Carrinho.aspx.cs" ValidateRequest="false"
EnableEventValidation="false" Inherits="Femsa.MerchToolbox.Carrinho" UICulture="pt-BR" Culture="pt-BR" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
<meta http-equiv="PRAGMA" content="NO-CACHE">
<meta http-equiv="content-language" content="pt">
<head runat="server">
<title>Untitled Page</title>
<link rel="stylesheet" href="lib/estilo.css" type="text/css" />
<link rel="stylesheet" href="lib/carrinho.css" type="text/css" />
<script type="text/javascript">
function mensagem() {
v_msg = "<h1 style='color:#98012e'>Atenção</h1><p style='font-size:14px'>O presente documento, após finalizado, figurará para a FCB como pedido de compra, ou seja, um compromisso de aquisição dos itens junto aos fornecedores.<br />Todos os pedidos estão sujeitos à confirmação, pois têm quantidades mínimas a serem alcançadas nacionalmente.<br /><br />Período de Compra Centralizada: <span style='color:#98012e'>nov/08 a fev/09</span>.</p><br /><br /><p align='right'><a href='#' onclick=\"parent.closeMessage();return false\">Fechar</a></p>";
parent.displayStaticMessage(v_msg, "modalDialog_contentDiv");
return false;
}
</script>
<script language="javascript" type="text/javascript" src="lib/AjaxCarrinho.js"></script>
</head>
<body onload="//javascript:mensagem();" style="overflow-x:hidden; overflow-y:auto;">
<form id="form1" runat="server">
<asp:Button ID="btnSubmit" Style="display: none;" runat="server" />
<div id="menu_carro">
<p style="border-bottom: 1px solid; margin: 0px">
Menu</p>
<asp:Button ID="btnSalvar" Style="background: #ddd; border-style: none; color: #555;
margin: 0px; width: 95px; height: 25px; cursor: pointer; text-align: left" runat="server"
Text="Salvar carrinho" OnClick="btnSalvar_Click" Width="86px" />
<asp:Button ID="btnExcel" Style="background: #ddd; border-style: none; color: #555;
margin: 0px; width: 95px; height: 25px; cursor: pointer; text-align: left" runat="server"
Text="Salvar EXCEL" OnClick="btnExcel_Click" Width="86px" />
<asp:Button ID="btnAtualizar" Style="background: #ddd; border-style: none; color: #555;
margin: 0px; width: 95px; height: 25px; cursor: pointer; text-align: left" runat="server"
Text="Atualizar Valores" OnClick="btnAtualizar_Click" Width="86px" />
</div>
<div id="tab_carro">
<asp:GridView ID="GridView1" BorderWidth="0px" Width="550px" CellPadding="2" CellSpacing="1"
runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound"
ShowFooter="true" DataSourceID="SqlDataSource1">
<HeaderStyle BackColor="#98012E" Height="25px" ForeColor="#FFFFFF" Font-Size="13px"
Font-Bold="true" VerticalAlign="Bottom" />
<FooterStyle BackColor="#98012E" Height="25px" ForeColor="#FFFFFF" Font-Size="13px"
Font-Bold="true" VerticalAlign="Bottom" HorizontalAlign="Center" />
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Marca">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("marca") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Produto">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("produto") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Compra minima">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("min_brasil") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Qtde compra">
<ItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" size="4" Text='<%# Bind("qtde") %>'></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Valor unit">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("prc1") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Valor total">
<ItemTemplate >
<asp:Label ID="Label6" runat="server" Text='<%# Bind("ptotal") %>'></asp:Label>
<%--<asp:TextBox ID="TextBox6" Visible="false" runat="server" size="12" Text='<%# Bind("num_pedido") %>'></asp:TextBox>--%>
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Bind("id_per") %>' />
<asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Bind("id_usr") %>' />
<asp:HiddenField ID="HiddenField3" runat="server" Value='<%# Bind("id_prod") %>' />
<asp:HiddenField ID="HiddenField4" runat="server" Value='<%# Bind("confirmado") %>' />
<asp:HiddenField ID="HiddenField5" runat="server" Value='<%# Bind("punit") %>' />
<asp:HiddenField ID="HiddenField6" runat="server" Value='<%# Bind("num_pedido") %>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="">
<ItemTemplate>
<%--<asp:ImageButton ID="imgExcluir" runat="server" ImageUrl="imagens/del.gif" onclick="<%# "javascript:ExcluirProduto('" + DataBinder.Eval(Container.DataItem, "id_compra") + "'); history.go(0);" %>" />--%>
<img src="imagens/del.gif" onclick="<%# "javascript:ExcluirProduto('" + DataBinder.Eval(Container.DataItem, "id_compra") + "'); history.go(0);" %>"
style="cursor: pointer" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:HiddenField ID="hdfUsuario" runat="server" />
<br>
<div>
<asp:GridView ID="GridView2" BorderWidth="0px" Width="550px" CellPadding="2" CellSpacing="1"
runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView2_RowDataBound"
ShowFooter="true" DataSourceID="SqlDataSource1" Style="display: none">
<HeaderStyle BackColor="#98012E" Height="25px" ForeColor="#FFFFFF" Font-Size="13px"
Font-Bold="true" VerticalAlign="Bottom" />
<FooterStyle BackColor="#98012E" Height="25px" ForeColor="#FFFFFF" Font-Size="13px"
Font-Bold="true" VerticalAlign="Bottom" HorizontalAlign="Center" />
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Marca">
<ItemTemplate>
<asp:Label ID="Label_1" runat="server" Text='<%# Bind("marca") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Produto">
<ItemTemplate>
<asp:Label ID="Label_2" runat="server" Text='<%# Bind("produto") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Compra minima">
<ItemTemplate>
<asp:Label ID="Label_4" runat="server" Text='<%# Bind("min_brasil") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Qtde compra">
<ItemTemplate>
<asp:Label ID="Label_5" runat="server" Text='<%# Bind("qtde") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Valor unit">
<ItemTemplate>
<asp:Label ID="Label_3" runat="server" Text='<%# Bind("prc1") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Valor total">
<ItemTemplate>
<asp:Label ID="Label_6" runat="server" Text='<%# Bind("ptotal") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:femsaConnectionString %>"
SelectCommand="SELECT tb_carrinho.id_compra, tb_carrinho.confirmado, tb_carrinho.id_per, tb_carrinho.id_usr, tb_carrinho.id_prod, tb_produto.produto, tb_carrinho.qtde, tb_carrinho.num_pedido, tb_carrinho.punit, tb_carrinho.ptotal,tb_produto.min_brasil,tb_produto.prc1, tb_produto.prd_tit, tb_marcas.marca FROM tb_carrinho INNER JOIN tb_produto ON tb_carrinho.id_prod = tb_produto.id INNER JOIN tb_marcas ON tb_produto.id_mk = tb_marcas.id
Where tb_carrinho.id_usr = @id_usr">
<SelectParameters>
<asp:ControlParameter ControlID="hdfUsuario" Name="id_usr" PropertyName="Value" />
</SelectParameters>
</asp:SqlDataSource>
</form>
<br />
</body>
</html>
Codigo C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data.Common;
namespace Femsa.MerchToolbox
{
public partial class Carrinho : System.Web.UI.Page
{
decimal valorTotal = 0, somaFinal = 0;
int contador = 0;
string nomeUsuario, nomeUsuarioDetalhe;
decimal pfinal = 0;
protected void Page_Load(object sender, EventArgs e)
{
Page.RegisterStartupScript("usuarioLogado", "<script language=\"javascript\">var usuario_id = '" + Session["usuarioID"] + "';</script>");
hdfUsuario.Value = "" + Session["usuarioID"];
nomeUsuario = hdfUsuario.Value;
nomeUsuarioDetalhe = "" + Session["usuarioName"];
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
ValoresSoma();
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[4].Text = "Total: ";
e.Row.Cells[5].Text = Convert.ToString(somaFinal);
}
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
ValoresSoma();
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[4].Text = "Total: ";
e.Row.Cells[5].Text = Convert.ToString(somaFinal);
}
}
protected void btnAtualizar_Click(object sender, EventArgs e)
{
if (GridView1.Rows.Count > 0)
{
ValoresSoma();
Salvar();
}
}
protected void ValoresSoma()
{
int total_itens = 0, item_selec = 0;
string valorSomaTotal;
decimal total, qtde_compra, punit;
total_itens = GridView1.Rows.Count;
if (total_itens > 0)
{
for (item_selec = 0; item_selec < total_itens; item_selec++)
{
qtde_compra = Convert.ToDecimal(((TextBox)GridView1.Rows[item_selec].Cells[3].FindControl("TextBox5")).Text);
punit = Convert.ToDecimal(((Label)GridView1.Rows[item_selec].Cells[4].FindControl("Label3")).Text);
total = qtde_compra * punit;
valorSomaTotal = Convert.ToString(Convert.ToDecimal(total));
((Label)GridView1.Rows[item_selec].Cells[5].FindControl("Label6")).Text = valorSomaTotal;
// somaFinal = somaFinal + Convert.ToDecimal(((Label)GridView1.Rows[item_selec].Cells[5].FindControl("Label6")).Text);
}
}
total_itens = GridView2.Rows.Count;
item_selec = 0;
somaFinal = 0;
for (item_selec = 0; item_selec < total_itens; item_selec++)
{
qtde_compra = Convert.ToDecimal(((Label)GridView2.Rows[item_selec].Cells[3].FindControl("Label_5")).Text);
punit = Convert.ToDecimal(((Label)GridView2.Rows[item_selec].Cells[4].FindControl("Label_3")).Text);
total = qtde_compra * punit;
valorSomaTotal = Convert.ToString(Convert.ToDecimal(total));
((Label)GridView2.Rows[item_selec].Cells[5].FindControl("Label_6")).Text = valorSomaTotal;
somaFinal = somaFinal + Convert.ToDecimal(((Label)GridView2.Rows[item_selec].Cells[5].FindControl("Label_6")).Text);
}
}
protected void btnSalvar_Click(object sender, EventArgs e)
{
if (GridView1.Rows.Count > 0)
{
ValoresSoma();
Salvar();
}
}
protected void Salvar()
{
int total_itens = 0, item_selec = 0;
string marca, produto, qtde_ant, qtde_min, qtde_compra, pedido, id_item, id_usuario, id_prod, confirmado, punit, ptotal;
total_itens = GridView1.Rows.Count;
id_item = ((HiddenField)GridView1.Rows[0].Cells[5].FindControl("HiddenField1")).Value;
//Excluir itens antigos
id_usuario = hdfUsuario.Value;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["femsaConnectionString"].ToString());
con.Open();
SqlCommand cmdDel = new SqlCommand("sp_delCarrinho", con);
cmdDel.CommandType = CommandType.StoredProcedure;
cmdDel.Parameters.AddWithValue("@id_usr", id_usuario);
cmdDel.ExecuteNonQuery();
//Adicionar itens novos
if (total_itens > 0)
{
SqlCommand cmdIns = new SqlCommand("PROC_tb_carrinho_INC", con);
for (item_selec = 0; item_selec < total_itens; item_selec++)
{
cmdIns.Parameters.Clear();
marca = ((Label)GridView1.Rows[item_selec].Cells[0].FindControl("Label1")).Text;
produto = ((Label)GridView1.Rows[item_selec].Cells[1].FindControl("Label2")).Text;
qtde_ant = ((Label)GridView1.Rows[item_selec].Cells[4].FindControl("Label3")).Text;
qtde_min = ((Label)GridView1.Rows[item_selec].Cells[2].FindControl("Label4")).Text;
qtde_compra = ((TextBox)GridView1.Rows[item_selec].Cells[3].FindControl("TextBox5")).Text;
pedido = ((HiddenField)GridView1.Rows[item_selec].Cells[5].FindControl("HiddenField6")).Value;
id_usuario = ((HiddenField)GridView1.Rows[item_selec].Cells[5].FindControl("HiddenField2")).Value;
id_prod = ((HiddenField)GridView1.Rows[item_selec].Cells[5].FindControl("HiddenField3")).Value;
confirmado = ((HiddenField)GridView1.Rows[item_selec].Cells[5].FindControl("HiddenField4")).Value;
punit = ((HiddenField)GridView1.Rows[item_selec].Cells[5].FindControl("HiddenField5")).Value;
ptotal = ((Label)GridView1.Rows[item_selec].Cells[5].FindControl("Label6")).Text;
cmdIns.CommandType = CommandType.StoredProcedure;
cmdIns.Parameters.AddWithValue("@id_per", Convert.ToInt32(id_item));
cmdIns.Parameters.AddWithValue("@id_usr", id_usuario);
cmdIns.Parameters.AddWithValue("@id_prod", Convert.ToInt32(id_prod));
cmdIns.Parameters.AddWithValue("@qtde", Convert.ToInt32(qtde_compra));
cmdIns.Parameters.AddWithValue("@num_pedido", Convert.ToInt32(pedido));
cmdIns.Parameters.AddWithValue("@confirmado", Convert.ToBoolean(confirmado));
cmdIns.Parameters.AddWithValue("@punit", Convert.ToDecimal(punit));
cmdIns.Parameters.AddWithValue("@ptotal", Convert.ToDecimal(ptotal));
cmdIns.ExecuteNonQuery();
}
con.Close();
Response.Redirect(Request.UrlReferrer.ToString(), true);
}
}
protected void btnExcel_Click(object sender, EventArgs e)
{
if (GridView1.Rows.Count > 0)
{
ValoresSoma();
PreExport();
}
}
protected void PreExport()
{
PrepareGridViewForExport(GridView2);
ExportGridView();
}
private void ExportGridView()
{
string attachment = "attachment; filename=Carrinho_" + nomeUsuarioDetalhe + ".xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("ISO-8859-1");
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView2.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
private void PrepareGridViewForExport(Control gv)
{
LinkButton lb = new LinkButton();
Literal l = new Literal();
string name = String.Empty;
for (int i = 0; i < gv.Controls.Count; i++)
{
string a;
a = Convert.ToString(gv.Controls[i].GetType());
if (gv.Controls[i].GetType() == typeof(LinkButton))
{
l.Text = (gv.Controls[i] as LinkButton).Text;
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
else if (gv.Controls[i].GetType() == typeof(DropDownList))
{
l.Text = (gv.Controls[i] as DropDownList).SelectedItem.Text;
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
else if (gv.Controls[i].GetType() == typeof(CheckBox))
{
l.Text = (gv.Controls[i] as CheckBox).Checked ? "True" : "False";
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
//else if (gv.Controls[i].GetType() == typeof(HiddenField))
//{
// // l.Text = (gv.Controls[i] as HiddenField).Value;
// gv.Controls.Remove(gv.Controls[i]);
// //gv.Controls.AddAt(i, l);
//}
//else if (gv.Controls[i].GetType() == typeof(TextBox))
//{
// l.Text = (gv.Controls[i] as TextBox).Text;
// gv.Controls.Remove(gv.Controls[i]);
// gv.Controls.AddAt(i, l);
//}
//else if (gv.Controls[i].GetType() == typeof(HtmlImage))
//{
// // l.Text = (gv.Controls[i] as Image).Text;
// gv.Controls.Remove(gv.Controls[i]);
// //gv.Controls.AddAt(i, l);
//}
if ((gv.Controls[i].HasControls()) && i != 6)
{
PrepareGridViewForExport(gv.Controls[i]);
}
}
}
}
}
Tiago Leite
Curtir tópico
+ 0Posts
11/03/2009
[devmedia .net]
Você quer que seu grid fique igual ao da imagem do excel que você enviou ?
Que tenha seu nome acima do cabeçalho do grid ?? E quer exportar para excel o grid que for gerado ?
Bom , eu vejo que seu método para exportar para excel já está implementado, O que precisa mesmo é saber como colocar outro cabeçalho no GridView ??
Não entedi o que quis dizer com vários cabeçalhos um em cima do outro.. pode ser mais específico ?? No aguardo... Abraços Carlos JR
Gostei + 0
11/03/2009
Tiago Leite
Na verdade, meu nome e endereço tambem são dados vindo do banco de dados, como é mais que um campo seria mais do que um cabeçalho, ou seja, se fosse apenas o campo nome seria apenas um cabeçalho a mais, por ser nome, endereço e CPF por exemplo seria 3 cabeçalhos a mais, ou seja eu quero trazer mais do que um cabeçalho no topo do gridview, o nome em cima do CPF que por sua vez estaria em cima do endereço, por isso seria um em cima do outro, a ideia é que eu consiga flexibilidade, ou seja mais de um.
Obrigado
Tiago Leite
Gostei + 0
11/03/2009
[devmedia .net]
{
LinkButton lb = new LinkButton();
Literal l = new Literal();
//Colocar as informações de nome e etc no Literal separando // Se reparar é isso que o método faz, joga as informações no Literal // Portanto é só alterá-lo l.Text = "Thiago <br>" l.Text = "CPF: 1231231231 <br>" l.Text = "Telefone: 1231231231 <br>"
string name = String.Empty;
for (int i = 0; i < gv.Controls.Count; i++)
{
string a;
a = Convert.ToString(gv.Controls[i].GetType());
if (gv.Controls[i].GetType() == typeof(LinkButton))
{
l.Text = (gv.Controls[i] as LinkButton).Text;
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
else if (gv.Controls[i].GetType() == typeof(DropDownList))
{
l.Text = (gv.Controls[i] as DropDownList).SelectedItem.Text;
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
else if (gv.Controls[i].GetType() == typeof(CheckBox))
{
l.Text = (gv.Controls[i] as CheckBox).Checked ? "True" : "False";
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
//else if (gv.Controls[i].GetType() == typeof(HiddenField))
//{
// // l.Text = (gv.Controls[i] as HiddenField).Value;
// gv.Controls.Remove(gv.Controls[i]);
// //gv.Controls.AddAt(i, l);
//}
//else if (gv.Controls[i].GetType() == typeof(TextBox))
//{
// l.Text = (gv.Controls[i] as TextBox).Text;
// gv.Controls.Remove(gv.Controls[i]);
// gv.Controls.AddAt(i, l);
//}
//else if (gv.Controls[i].GetType() == typeof(HtmlImage))
//{
// // l.Text = (gv.Controls[i] as Image).Text;
// gv.Controls.Remove(gv.Controls[i]);
// //gv.Controls.AddAt(i, l);
//}
if ((gv.Controls[i].HasControls()) && i != 6)
{
PrepareGridViewForExport(gv.Controls[i]);
}
}
Gostei + 0
13/03/2009
[devmedia .net]
Gostei + 0
16/03/2009
Tiago Leite
Eu ainda estou tentando resolver, não consegui ainda, te passarei mais detalhado outra duvidas nesse chamado caso não consiga concluir o desenvolvimento
Gostei + 0
16/03/2009
[devmedia .net]
Gostei + 0
16/03/2009
Devmedia
Gostei + 0
17/03/2009
Tiago Leite
Não consegui inserir os dados.Tentei de tudo que é jeito
A principio eu tinha inserido essa parte que vocÊ tinha me passado:
l.Text = "Tiago <br>";
l.Text = "CPF: 1231231231 <br>";
l.Text = "Telefone: 1231231231 <br>";
Gostei + 0
17/03/2009
[devmedia .net]
Eu falei para você alterar seu método de exportação apara adaptar a sua realidade, só adicionar as linhas não adiante... veja abaixo Coloque a linha abaixo... ficando assim.. Só que deve colocar isso dentro do for que está no método.. Adicione as linhas em negrito string name = String.Empty;
for (int i = 0; i < gv.Controls.Count + 1; i++)
{ l.Text = "Thiago <br>" l.Text = "CPF: 1231231231 <br>" l.Text = "Telefone: 1231231231 <br>" gv.Controls.AddAt(i, l); string a;
a = Convert.ToString(gv.Controls[i].GetType());
if (gv.Controls[i].GetType() == typeof(LinkButton))
{
l.Text = (gv.Controls[i] as LinkButton).Text;
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
else if (gv.Controls[i].GetType() == typeof(DropDownList))
{
l.Text = (gv.Controls[i] as DropDownList).SelectedItem.Text;
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
else if (gv.Controls[i].GetType() == typeof(CheckBox))
{
l.Text = (gv.Controls[i] as CheckBox).Checked ? "True" : "False";
gv.Controls.Remove(gv.Controls[i]);
gv.Controls.AddAt(i, l);
}
//else if (gv.Controls[i].GetType() == typeof(HiddenField))
//{
// // l.Text = (gv.Controls[i] as HiddenField).Value;
// gv.Controls.Remove(gv.Controls[i]);
// //gv.Controls.AddAt(i, l);
//}
//else if (gv.Controls[i].GetType() == typeof(TextBox))
//{
// l.Text = (gv.Controls[i] as TextBox).Text;
// gv.Controls.Remove(gv.Controls[i]);
// gv.Controls.AddAt(i, l);
//}
//else if (gv.Controls[i].GetType() == typeof(HtmlImage))
//{
// // l.Text = (gv.Controls[i] as Image).Text;
// gv.Controls.Remove(gv.Controls[i]);
// //gv.Controls.AddAt(i, l);
//}
if ((gv.Controls[i].HasControls()) && i != 6)
{
PrepareGridViewForExport(gv.Controls[i]);
}
}
Carlos Jr
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)