Bineeshcp Viswanath

Bineeshcp Viswanath

  • NA
  • 140
  • 39.4k

How to Display Image from Database in Modal Popup

Mar 30 2019 7:07 AM
Hello All,
 
I need your help to display image from database in modal popup window in asp.net application.
 
I have mentioned my code for your reference.
 
Here my htm code:-
  1. <div class="modal fade" id="myModal">  
  2. <div class=" modal-dialog modal-dialog-centered">  
  3. <div class="modal-content">  
  4. <div class="modal-header">  
  5. <h4 class="modal-title">Image Details</h4>  
  6. </div>  
  7. <div class=" modal-body">  
  8. <img class="img-rounded" id="modal_Img" src='<%# Eval("Image")%>' style="width: 100%" runat="server" />  
  9. <br />  
  10. <asp:TextBox ID="tbxComment" CssClass="text-primary" Width="350px" TextMode="MultiLine" runat="server"></asp:TextBox>  
  11. </div>  
  12. <div class="modal-footer">  
  13. <button type="button" class="btn btn-primary" data-dismiss="modal">Save</button>  
  14. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>  
  15. </div>  
  16. </div>  
  17. </div>  
  18. </div>  
And below is the c# code:-
  1. private void LoadImageBasedOnFID(Int64 FID)  
  2. {  
  3. try  
  4. {  
  5. using (SqlCommand command = new SqlCommand("LoadImageBasedOnFID", clsConObj.sqlCon))  
  6. {  
  7. clsConObj.OpenConnection();  
  8. command.Parameters.Add("@FID", SqlDbType.SmallInt).Value = FID;  
  9. command.CommandType = CommandType.StoredProcedure;  
  10. using (SqlDataReader reader = command.ExecuteReader())  
  11. {  
  12. while (reader.Read())  
  13. {  
  14. modal_Img.Src = reader["Image"].ToString();  
  15. ClientScript.RegisterStartupScript(this.GetType(), "Pop""openModal();"true);  
  16. }  
  17. }  
  18. clsConObj.CloseConnection();  
  19. }  
  20. }  
  21. catch (Exception ex)  
  22. {  
  23. }  
  24. }  

Answers (1)