Sir,
Following code of GridView is working perfectly. Showing images also in GridView. However when we are exporting data of GridView into excel the picture is not export, while all data is going well into excel.
Please guide how to export including picture.
The folder name is "ABC" and then use Picture Path from database
(Like abc/0001/0001.jpg)
Thanks in advance
<div class="row">
<div class="col-xs-12">
<asp:Label ID="lblMessage" runat="server"></asp:Label>
<div style="height: 500px; width: 99%; overflow: auto">
<asp:GridView ID="gvDetail" runat="server" AllowPaging="false" ShowFooter="true"
CssClass="table table-bordered table-hover dataTable" AutoGenerateColumns="false" DataKeyNames="MemberID">
<Columns>
<asp:BoundField DataField="MemberFamilyName" SortExpression="MemberFamilyName" HeaderText="Member Family Name"></asp:BoundField>
<asp:BoundField DataField="MemberID" SortExpression="MemberID" HeaderText="ID"></asp:BoundField>
<asp:TemplateField HeaderText="Picture">
<ItemTemplate>
<asp:Image runat="server" ID="memberPic" Width="100px" hight="100px" ImageUrl='<%#DataBinder.Eval(Container.DataItem, "PicPath")%>' />
</ItemTemplate>
<ItemStyle Width="50px" />
</asp:TemplateField>
<asp:BoundField DataField="DOJ" SortExpression="DOJ" HeaderText="DOJ" DataFormatString="{0:dd-MMM-yyyy}" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
<asp:BoundField DataField="MemberShipDt" SortExpression="MemberShipDt" HeaderText="Membership Dt" DataFormatString="{0:dd-MMM-yyyy}" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
<asp:BoundField DataField="MemberShipNo" SortExpression="MemberShipNo" HeaderText="Membership No"></asp:BoundField>
<asp:BoundField DataField="MemberWithFather" SortExpression="MemberWithFather" HeaderText="Member Name With Father"></asp:BoundField>
<asp:BoundField DataField="DOB" SortExpression="DOB" HeaderText="Date of Birth" DataFormatString="{0:dd-MMM-yyyy}" ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
<asp:BoundField DataField="Gender1" SortExpression="Gender1" HeaderText="Gender"></asp:BoundField>
<asp:BoundField DataField="CellNo" SortExpression="CellNo" HeaderText="Contact No."></asp:BoundField>
<asp:BoundField DataField="CNICNo" SortExpression="CNICNo" HeaderText="CNIC No"></asp:BoundField>
<asp:BoundField DataField="Res_Address" SortExpression="Res_Address" HeaderText="Res. Address"></asp:BoundField>
<asp:BoundField DataField="Territory" SortExpression="Territory" HeaderText="City"></asp:BoundField>
<asp:BoundField DataField="BloodGroup" SortExpression="BloodGroup" HeaderText="Blood Group"></asp:BoundField>
<asp:BoundField DataField="Statu" SortExpression="Statu" HeaderText="Status" ItemStyle-HorizontalAlign="Center"></asp:BoundField>
<asp:BoundField DataField="MaritalStatus1" SortExpression="MaritalStatus1" HeaderText="Marital S"></asp:BoundField>
<asp:BoundField DataField="DeathOn" SortExpression="DeathOn" HeaderText="Death On" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:dd-MMM-yyyy}"></asp:BoundField>
<asp:BoundField DataField="Dues" SortExpression="Dues" HeaderText="Dues" DataFormatString="{0:n}">
<HeaderStyle CssClass="alignright" />
<ItemStyle Width="70px" CssClass="alignright" />
</asp:BoundField>
<%-- <asp:BoundField DataField="MonthlyStatus" SortExpression="MonthlyStatus" HeaderText="Monthly Status"></asp:BoundField>--%>
</Columns>
</asp:GridView>
<asp:TextBox ID="txtLastSortColumn" runat="server" Visible="False"></asp:TextBox>
</div>
</div>
</div>
<asp:LinkButton ID="lnkExcel" runat="server" CssClass="gridbuttonred" style="padding:4px; border-radius:0px">Export to Excel</asp:LinkButton>
Protected Sub lnkExcel_Click(sender As Object, e As EventArgs) Handles lnkExcel.Click
If gvDetail.Rows.Count = 0 Then
lblMessage.Text = " <div class=""alert alert-error""> No report for export. </div>"
Exit Sub
End If
' Dim a As String
Response.Clear()
Response.Buffer = True
Response.AddHeader("content-disposition", "attachment;filename=MemberList.xls")
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel"
Using sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
LoadReport()
gvDetail.HeaderRow.BackColor = Color.White
gvDetail.HeaderRow.Font.Size = "8"
gvDetail.FooterRow.Font.Size = "8"
gvDetail.FooterRow.Font.Bold = True
For Each cell As TableCell In gvDetail.HeaderRow.Cells
cell.BackColor = gvDetail.HeaderStyle.BackColor
cell.Font.Size = "8"
Next
For Each row As GridViewRow In gvDetail.Rows
row.BackColor = Color.White
For Each cell As TableCell In row.Cells
If row.RowIndex Mod 2 = 0 Then
cell.BackColor = gvDetail.AlternatingRowStyle.BackColor
Else
cell.BackColor = gvDetail.RowStyle.BackColor
End If
cell.CssClass = "textmode"
Next
Next
gvDetail.RenderControl(hw)
'style to format numbers to string
Dim style As String = "<style> .textmode {font-size:10px; } </style>"
Response.Write(style)
Response.Output.Write(sw.ToString())
Response.Flush()
Response.[End]()
End Using
End Sub
Public Overrides Sub VerifyRenderingInServerForm(control As Control)
' Verifies that the control is rendered
End Sub
Public Sub LoadReport()
Dim objReport As New clsmembers
Dim rsReport As New DataSet
objReport.CompanyID = cboCompany.SelectedValue
objReport.Status = cboType.SelectedValue
objReport.FamilyID = cboFamily.SelectedValue
objReport.BloodGroupID = cboBloodGroup.SelectedValue
objReport.DughterOfJamat = cboDaughter.SelectedValue
objReport.DuesPosition = "" ' cboDues.SelectedValue
objReport.MartialStatus = cboMartialStatus.SelectedValue
objReport.TransType = "21"
If objReport.LoadMembers(rsReport) = False Then
lblMessage.Text = " <div class=""alert alert-error""> " & objReport.ErrMessage & " </div>"
gvDetail.DataSource = Nothing
gvDetail.DataBind()
Exit Sub
End If
If rsReport.Tables(0).Rows.Count = 0 Then
lblMessage.Text = " <div class=""alert alert-info""> No record exist </div>"
gvDetail.DataSource = Nothing
gvDetail.DataBind()
Else
lblMessage.Text = ""
End If
gvDetail.DataSource = rsReport.Tables(0).DefaultView
gvDetail.DataBind()
If gvDetail.Rows.Count > 0 Then
divOptions.Visible = True
Else
divOptions.Visible = False
End If