Edit Update Binary Image using jQuery Ajax and Generic Handler in ASP.Net

Last Reply 8 months ago By pandeyism

Posted 8 months ago

how can i edit update binary image and name using jquery ajax json web method in the json table itself (with file upload and textbox as edit controls)

with below code showing name in textbox and binary image details in file upload control.

script type="text/javascript">
    $(function () {
        Getdetails();
    });
    function Getdetails() {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "WebService.asmx/GetProducts",
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.d.length; i++) {
                    var id = data.d[i].Id;
                  
                    var image = "data:image/jpg;base64," + data.d[i].ProdImage;
                    $("#ttablepdtgrid").append(
                    "<div class=trclass>" +
                    "   <tr><td class=tdcolumn>" +
                    "       <div class=tabledivprod>" +
                    "           <img class=pdtimgclnt src='" + image + "' />" +
                   
                    "           <div class=PdtID>" + id + "</div>" +
   				'<p><a class="btn" data-id="' + data.d[i].id + '" id=btnedit role="button" >edit</a></p>' +
                    "           <br /><br />" +
                    "       </div>" +
                    "   </td></tr>" +
                    "</div>");
                }
            },
            error: function (response) {
                alert("Error while Showing update data");
            }
        });
    }
</script>
 

 

<div id="ttablepdtgrid">
</div>

 

    [WebMethod]
    public List<Product> GetProducts()
    {
        List<Product> products = new List<Product>();
        string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        string query = "SELECT * FROM tblFiles";
        using (SqlConnection con = new SqlConnection(conString))
        {
            SqlCommand cmd = new SqlCommand(query, con);
            con.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                products.Add(new Product
                {
                    Id = Convert.ToInt32(sdr["Id"]),
                    
                    ProdImage = Convert.ToBase64String((byte[])sdr["Data"], 0, ((byte[])sdr["Data"]).Length)
                });
            }
            con.Close();
        }
 
        return products;
    }
 
    public class Product
    {
        public int Id { get; set; }
     
        public string ProdImage { get; set; }
    }

 

This question does not have replies that have been liked.