Hi AliYilmaz,
See there is no need to loop for getting the textboxes or other elements values because you can access them just passing index in it i.e 0 or 1.
Let me explain you in more detail
For eg.
Your second gridview contains 3 records then your "SiparisDetay's" data contains three records which include textboxes and other elements value in it but all the three records where you are saving the textboxes and other elements value will be same of three records so for accessing those values there is no need of running loop you can get it by passing index in it either 0 or else so for more detail refer below screenshot where you will get more detail about it and refer the code
In HTML part below code is added in sample
<asp:TextBox ID="txtFirstTextBox" runat="server" />
<br />
<asp:TextBox ID="txtSecondTextBox" runat="server" />
<br />
<asp:DropDownList ID="ddlValues" runat="server">
<asp:ListItem Value="Value 1" Text="Value 1" />
<asp:ListItem Value="Value 2" Text="Value 2" />
<asp:ListItem Value="Value 3" Text="Value 3" />
<asp:ListItem Value="Value 4" Text="Value 4" />
<asp:ListItem Value="Value 5" Text="Value 5" />
</asp:DropDownList>
And jQuery code
<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.firstTextBoxValue = $("[id*=txtFirstTextBox]").val();
obj.secondTextBoxValue = $("[id*=txtSecondTextBox]").val();
obj.dropDownListValue = $("[id*=ddlValues] option:selected").val();
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) {
alert(response.d);
}
});
return false;
});
});
</script>
C#
[WebMethod]
public static string SaveRecords(List<UrunlerData> Data)
{
string firstTextBox = Data[0].firstTextBoxValue;
string SecondTextBox = Data[0].secondTextBoxValue;
string dropdownlistTextBox = Data[0].dropDownListValue;
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 "";
}
public class UrunlerData
{
public string firstTextBoxValue { get; set; }
public string secondTextBoxValue { get; set; }
public string dropDownListValue { 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; }
}
Screenshot
