I am adding gridview data into data base every thing is fine but problem is that when there are no row then it give the message Data scessfully saved but I want it give me message when data entered into data base. When there are no data into data base it give me message there are no row in grid view .
Following my code
Function AddGridviewData() {
var AddRow = new Array();
if (count = $get("id*=Test_gridview]").rows.length != 1) {////length mention because I have one row into gridview but there are no data in that row means empty.
$('[id*=Test_gridview]').find('tr:has(td)').each(function () {
var NewRow = {};
NewRow. id = $(this).find("td:eq(1)").html();
NewRow.name = $(this).find("td:eq(2)").html();
NewRow.sum = $(this).find("td:eq(1)").html();
AddRow.push(NewRow);
});
$.ajax({
type: 'POST',
url: "TestPage.aspx/SaveGridViewRowData",
data: '{AddRow: ' + JSON.stringify(AddRow) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("Data scessfully saved ");
return false;
}
});
return false;
else
{
alert("No Row in Gridview ");
}
};
My WebMethod.
public partial class Detail
{
Public int {
public string Name { get; set; }
}
[System.Web.Services.WebMethod]
public static void SaveGridViewRowData(List<Detail> AddRow)
{
using (var db = new TestEntities()/////////////My Entity Frame work name
foreach (Detail NewRow in AddRow)////Detail class name///
{
db.StoredProcedure1(
NewRow.Id
NewRow.Name
NewRow.sum
);
}
return "Data Inserted";
}
Please help me how I show message (Data Successfully saved) when data entered into data base when there are no row show (No Row in gridview)