Bonjour, j'ai un gridview que je vais exporter vers excel sauf que ce dernier contient un lien mon but est d'exporter mon gridview sans ce lien. mon code actuel est :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 
 protected void ExporterTout_Click(object sender, EventArgs e)
    {
        if (gridRecherche.Rows.Count == 0)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Information", "alert('Aucune information à télécharger');", true);
        }
        else
        {
            string nmFile = "Export_" + System.DateTime.Now.Day + "_" + System.DateTime.Now.Month + "_" + System.DateTime.Now.Year + ".xls";
 
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=" + nmFile);
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-excel";
 
            using (StringWriter sw = new StringWriter())
            {
                HtmlTextWriter hw = new HtmlTextWriter(sw);
 
                //To Export all pages
                gridRecherche.AllowPaging = false;
                this.fillGridRecherche();
 
                gridRecherche.HeaderRow.BackColor = Color.White;
                foreach (TableCell cell in gridRecherche.HeaderRow.Cells)
                {
                    cell.BackColor = gridRecherche.HeaderStyle.BackColor;
                }
                foreach (GridViewRow row in gridRecherche.Rows)
                {
                    row.BackColor = Color.White;
                    foreach (TableCell cell in row.Cells)
                    {
                        if (row.RowIndex % 2 == 0)
                        {
                            cell.BackColor = gridRecherche.AlternatingRowStyle.BackColor;
                        }
                        else
                        {
                            cell.BackColor = gridRecherche.RowStyle.BackColor;
                        }
                        cell.CssClass = "textmode";
                    }
                }
 
                gridRecherche.RenderControl(hw);
 
                //style to format numbers to string
                string style = @"<style> .textmode { } </style>";
                Response.Write(style);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }
        }
    }