Click here to Skip to main content
15,914,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
how to check data is exists or not in jquery ajax with asp.net..


$(document).ready(function () {
$("#txtFname").keyup(function () {
var findName = $("#txtFname").val()
// var len = 0;
len = findName.length;
if (findName != "") {

// alert(findName);
$.ajax
({
method: "GET",
url: "../Jquery_Examples /save_Employee_Jquery.aspx?findName=" + findName,
success: function (data) {
$("#bindData").html(data);

}
});
}
});

// bindData is HTML Div..

// my C# code.

in pageload method i get query string values..
string findName = Request.QueryString["findName"].ToString();
if (findName != null)
{
findData(findName);
}

// FinData method


private void findData(string findName)
{

try
{
conn = new SqlConnection(getConnection);

conn.Open();

string query = "select * from EmployeeData WHERE Fname LIKE @findName + '%'";
cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@findName", findName);
SqlDataReader reader = cmd.ExecuteReader();

DataTable dt = new DataTable();
dt.Load(reader);
if (dt.Rows.Count > 0)
{
GrdEmployee.DataSource = dt;
GrdEmployee.DataBind();

GrdEmployee.Visible = true;
}
}

What I have tried:

how to check Data is Exist or not Jquery AJAX in asp.net . then show message if data is found show found data and data not show not data
Posted
Updated 1-Jan-19 5:28am

1 solution

Hi,
you can check by below code in jquery.

$.ajax
({
method: "GET",
url: "../Jquery_Examples /save_Employee_Jquery.aspx?findName=" + findName,
success: function (data) {
$("#bindData").html(data);
if(<data && data!=null)
{
   alert('show found data');
}
else
{
 alert('data not show not data');
 }
}
});
}
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900