kats9993 says:
<asp:GridView ID="GridView1" style="margin:auto" runat="server"
AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" Width="690px"
CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<Columns>
<asp:BoundField DataField="id" HeaderText="Diamonds Pdf" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Literal ID="ltEmbed" runat="server" />
</ItemTemplate>
</ asp:GridView>
replace above code with below
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="Id" HeaderText="File Id" />
<asp:BoundField DataField="Name" HeaderText="File Name" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<iframe id="ifDisplayPDF" runat="server"></iframe>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
kats9993 says:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string embed = "<object data=\"{0}{1}\" type=\"application/pdf\" width=\"500px\" height=\"500px\">";
embed += "If you are unable to view file, you can download from <a href = \"{0}{1}&download=1\">here</a>";
embed += "</object>";
int Data = Convert.ToInt32(e.Row.Cells[0].Text);
(e.Row.FindControl("ltEmbed") as Literal).Text = string.Format(embed, ResolveUrl("~/File.ashx?Id="), Data);
e.Row.Cells[0].Visible = false;
}
}
and replace above code with below
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int Data = Convert.ToInt32(e.Row.Cells[0].Text);
(e.Row.FindControl("ifDisplayPDF") as HtmlControl).Attributes["src"] = ResolveUrl("~/File.ashx?Id=" + Data);
e.Row.Cells[0].Visible = false;
}
}