Dawood Abbas

Dawood Abbas

  • NA
  • 264
  • 98.4k

Cant get data from C#, returned one row table data in json?

Sep 23 2015 1:08 AM
[WebMethod]
public static GalleryDetailsInPopup[] BindDatatable(int imageId)
{
DataTable dt = new DataTable();
List<GalleryDetailsInPopup> details = new List<GalleryDetailsInPopup>();
using (SqlConnection con = new SqlConnection("Server=SERVER1; Database=WomensClothing; uid=sa; pwd=elife@123"))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "Get_galleryImages";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@imageId", imageId);
cmd.Connection = con;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dtrow in dt.Rows)
{
GalleryDetailsInPopup popupDetails = new GalleryDetailsInPopup();
popupDetails.ImageId = Convert.ToInt32(dtrow["ImageId"].ToString());
popupDetails.OwnerName = dtrow["OwnerName"].ToString();
popupDetails.FrontImage = dtrow["FrontImage"].ToString();
popupDetails.BackImage = dtrow["BackImage"].ToString();
popupDetails.DesignedBy = dtrow["DesignedBy"].ToString();
popupDetails.FrontStyle = dtrow["FrontStyle"].ToString();
popupDetails.BackStyle = dtrow["BackStyle"].ToString();
popupDetails.BodyFabric = dtrow["BodyFabric"].ToString();
popupDetails.SleeveFabric = dtrow["SleeveFabric"].ToString();
popupDetails.YokeFabric = dtrow["YokeFabric"].ToString();
popupDetails.CollerFabric = dtrow["CollerFabric"].ToString();
popupDetails.Price = Convert.ToDouble(dtrow["Price"].ToString());
details.Add(popupDetails);
}
}
}
return details.ToArray();
}
 
 
$(document).on("click", "[id*=link" + data.d[i].ImageId + "]", function () {
var imageId = $(this).closest("td").find('span').html();
alert(imageId);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "gallries.aspx/BindDatatable",
data: "{'imageId':'" + imageId + "'}",
dataType: "json",
success: function (popup) {
var frontstyles = popup.ImageId;
alert(frontstyles);
},
error: function (result) {
alert("Error");
}
});
});
 
 
 
 
 
 
 
 

Answers (1)