Trouble exporting GridView with CheckBoxes RRS feed

  • Question

  • User615288127 posted

    I'm using Visual Studio 2015 with SQL Server 2014, VB.

    I have a GridView where the first two columns are checkboxes.  I'm using the routine below to export the GridView to Excel.  The issue I'm having is how to put an "X" in the first two columns whenever the checkbox is checked.  As of now the first two columns are empty when exported.  My columns are named as follows:

    PDF, SLDPRT, PCB Footprint, Description, Height, Comments;  the first two columns are templates, all others are bound datafields.


            If (E1 = True Or E2 = True) And (E3 = False) Then
                Response.Buffer = True
                Response.AddHeader("content-disposition", String.Format("inline; filename={0}Cutouts_and_Holes.xls", Request.QueryString("Data")))
                If E1 = True Then Response.ContentType = "application/vnd.ms-excel"
                If E2 = True And E1 = False Then Response.ContentType = "application/vnd.scalc.exe -o %1"
                Dim stringWriter As New StringWriter()
                Dim htmlTextWriter As New HtmlTextWriter(stringWriter)
                GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF")    'white; middle blue #3399FF
                For index As Integer = 0 To GridView1.HeaderRow.Cells.Count - 1
                    GridView1.HeaderRow.Cells(index).Style.Add("background-color", "#969696")   'orange, was #d17250
                Dim index2 As Integer = 1
            End If


    <asp:GridView ID="GridView1" runat="server" 
            AutoGenerateColumns="False" CellPadding="4" DataKeyNames="PCB Footprint" 
            DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" 
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <asp:TemplateField HeaderText="PDF">
                        <asp:CheckBox ID="PDF" runat="server" AutoPostBack="True" />
                <asp:TemplateField HeaderText="SLDPRT">
                        <asp:CheckBox ID="SLDPRT" runat="server" AutoPostBack="True" />
                <asp:BoundField DataField="PCB Footprint" HeaderText="PCB Footprint" 
                    ReadOnly="True" SortExpression="PCB Footprint" />
                <asp:BoundField DataField="Description" HeaderText="Description" 
                    SortExpression="Description" />
                <asp:BoundField DataField="Height" HeaderText="Height" 
                    SortExpression="Height" />
                <asp:BoundField DataField="Comments" HeaderText="Comments" 
                    SortExpression="Comments" />
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />

    The basic question is: does anybody know how I can get an "X" to appear in the exported file where either of the first two column checkboxes are checked?


    Thursday, February 9, 2017 12:24 AM