edit update binary image and name using jquery ajax json

Last Reply 3 days ago By pandeyism

Posted 7 days 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; }
    }

 

You are viewing reply posted by: pandeyism 4 days ago.
Posted 4 days ago

I am working on it once done will get back to you.