Hi AliYilmaz,
Instead of calling SaveRecords Method everytime we can call it one time by passing the list of values and in SaveRecords method you can run a loop where you can check for a orderId duplicate value so refer below code you need to change jQuery code previous one with below
<script type="text/javascript">
$(function () {
$('[id*=btnSave]').click(function () {
var Data = [];
$("[id*=gvCopied]").find("tr:not(:nth-child(1)):not(:nth-child(2))").each(function () {
var obj = {};
obj.texboxValue = "Test";
obj.urunAd = $(this).find('td').eq(0).html();
obj.stok = $(this).find('td').eq(1).html();
obj.seriNo = $(this).find('td').eq(2).html();
obj.tedarikcilID = $(this).find('td').eq(3).html();
obj.Adet = $(this).find('td').eq(4).html();
obj.elemanSeç = $(this).find('td').eq(5).html();
obj.elemanAdet = $(this).find('td').eq(6).html();
obj.tedarikçiFiyat = $(this).find('td').eq(7).html();
Data.push(obj);
});
$.ajax({
url: "Default.aspx/SaveRecords",
data: '{ Data :' + JSON.stringify(Data) + '}',
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (response) {
}
});
return false;
});
});
</script>
and you need to create a Property class where you need to declare all the properties which you are going to pass through the ajax call so as per the sample your Property class will look like below so you need to change the property class according to your need.so refer below property class
public class UrunlerData
{
public string textboxValue { get; set; }
public string urunAd { get; set; }
public int stok { get; set; }
public string seriNo { get; set; }
public string tedarikcilID { get; set; }
public string Adet { get; set; }
public string elemanSeç { get; set; }
public string elemanAdet { get; set; }
public string tedarikçiFiyat { get; set; }
}
and now your SaveRecords Method will look like below
[WebMethod]
public static string SaveRecords(List<UrunlerData> Data)
{
List<UrunlerData> recievedDetails = Data;
for (int i = 0; i < recievedDetails.Count; i++)
{
//DO your code.
}
//Your Saving Code.
return "";
}
Suppose while looping you found the orderId which is already present in your database then you need to break the loop sending the messages
[WebMethod]
public static string SaveRecords(List<UrunlerData> Data)
{
List<UrunlerData> recievedDetails = Data;
for (int i = 0; i < recievedDetails.Count; i++)
{
int id = recievedDetails[i].stok;
if (id == 7) //Comapring your database value.
{
return "Your Message";
break;
}
//DO your code.
}
//Your Saving Code.
return "";
}
Once you done with above then you can get the message in return in success function of ajax call where you can display it with alert like below
$.ajax({
url: "Default.aspx/SaveRecords",
data: '{ Data :' + JSON.stringify(Data) + '}',
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (response) {
alert(response.d);
}
});