Question is Solved. It works like a charm. Please try it. Cheers
protected void ddComapanyFilter_SelectedIndexChanged(object sender, EventArgs e)
{
string id = ddlCountries.SelectedItem.Value;
string constr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM RetPDF WHERE id = @id",con);
cmd.Parameters.AddWithValue("@id", id);
using (var reader = cmd.ExecuteReader())
{
if (reader.Read())
{
byte[] bytes = (byte[])reader["Data"];
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/pdf";
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
con.Close();
}
}
}
<asp:DropDownList ID="ddlCountries" AppendDataBoundItems="true" EnableViewState="true" AutoPostBack="True" runat="server" OnSelectedIndexChanged="ddComapanyFilter_SelectedIndexChanged"><asp:ListItem value="0">Please Select PDF Files</asp:ListItem></asp:DropDownList>
<hr />