Please help search returns no record yet it returns message No records found for the search criteria.
yet there are records in the tabl.
please help where could the problem be.
<script src="../Scripts/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="../Scripts/ASPSnippets_Pager.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
GetCustomers(1);
});
$("[id*=txtSearch]").live("keyup", function () {
GetCustomers(parseInt(1));
});
$(".Pager .page").live("click", function () {
GetCustomers(parseInt($(this).attr('page')));
});
function SearchTerm() {
return jQuery.trim($("[id*=txtSearch]").val());
};
function GetCustomers(pageIndex) {
$.ajax({
type: "POST",
url: "StudentSearchnew.aspx/GetCustomers",
data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
var row;
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var customers = xml.find("Customers");
if (row == null) {
row = $("[id*=gvCustomers] tr:last-child").clone(true);
}
$("[id*=gvCustomers] tr").not($("[id*=gvCustomers] tr:first-child")).remove();
if (customers.length > 0) {
$.each(customers, function () {
var customer = $(this);
$("td", row).eq(0).html($(this).find("Name").text());
$("td", row).eq(1).html($(this).find("Account").text());
$("td", row).eq(2).html($(this).find("Class").text());
$("td", row).eq(3).html($(this).find("Stream").text());
$("td", row).eq(4).html($(this).find("STDTYPE").text());
$("td", row).eq(5).html($(this).find("ACNOS").text());
$("td", row).eq(6).html($(this).find("Sex").text());
$("td", row).eq(7).html($(this).find("House").text());
$("[id*=gvCustomers]").append(row);
row = $("[id*=gvCustomers] tr:last-child").clone(true);
});
var pager = xml.find("Pager");
$(".Pager").ASPSnippets_Pager({
ActiveCssClass: "current",
PagerCssClass: "pager",
PageIndex: parseInt(pager.find("PageIndex").text()),
PageSize: parseInt(pager.find("PageSize").text()),
RecordCount: parseInt(pager.find("RecordCount").text())
});
$(".ContactName").each(function () {
var searchPattern = new RegExp('(' + SearchTerm() + ')', 'ig');
$(this).html($(this).text().replace(searchPattern, "<span class = 'highlight'>" + SearchTerm() + "</span>"));
});
} else {
var empty_row = row.clone(true);
$("td:first-child", empty_row).attr("colspan", $("td", row).length);
$("td:first-child", empty_row).attr("align", "center");
$("td:first-child", empty_row).html("No records found for the search criteria.");
$("td", empty_row).not($("td:first-child", empty_row)).remove();
$("[id*=gvCustomers]").append(empty_row);
}
};
$(function () {
$("[id*=gvCustomers]").find("a").click(function () {
var row = $(this).closest("tr");
var customerid = row.find("td").eq(0).html();
var name = row.find("td").eq(1).html();
var country = row.find("td").eq(2).html();
var Stream = row.find("td").eq(3).html();
var Types = row.find("td").eq(4).html();
var Program = row.find("td").eq(5).html();
var Limit = row.find("td").eq(6).html();
var House = row.find("td").eq(7).html();
var Regno = row.find("td").eq(8).html();
document.getElementById("hfId").value = customerid;
document.getElementById("hfName").value = name;
document.getElementById("hfCountry").value = country;
document.getElementById("hfstream").value = Stream;
document.getElementById("hfTypes").value = Types;
document.getElementById("hfProgram").value = Program;
document.getElementById("hfLimit").value = Limit;
document.getElementById("hfHouse").value = House;
document.getElementById("hfRegno").value = Regno;
});
});
</script>
</head>
<body class="newStyle1">
<form id="form1" runat="server">
Search:
<asp:TextBox ID="txtSearch" runat="server" />
<hr />
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="False" Height="16px" Width="720px">
<Columns>
<asp:BoundField HeaderStyle-Width="150px" DataField="Account" HeaderText="Account" >
<HeaderStyle Width="150px"></HeaderStyle>
</asp:BoundField>
<asp:BoundField HeaderStyle-Width="150px" DataField="Name" HeaderText="Name"
ItemStyle-CssClass="ContactName" >
<HeaderStyle Width="150px"></HeaderStyle>
<ItemStyle CssClass="ContactName"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Class">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Class") %>'></asp:TextBox>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem Value="PRE"></asp:ListItem>
<asp:ListItem Value="P1"></asp:ListItem>
<asp:ListItem>P2</asp:ListItem>
<asp:ListItem>P3</asp:ListItem>
<asp:ListItem>P4</asp:ListItem>
<asp:ListItem>P5</asp:ListItem>
<asp:ListItem>P6</asp:ListItem>
<asp:ListItem>P7</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Class") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="150px" />
</asp:TemplateField>
<asp:BoundField DataField="Stream" HeaderText="Stream" />
<asp:BoundField DataField="Stdtype" HeaderText="STDTYPE" />
<asp:BoundField DataField="Sex" HeaderText="Sex" />
<asp:BoundField DataField="House" HeaderText="House" />
<asp:CommandField ShowSelectButton="True" />
<asp:TemplateField HeaderText="Check">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<div class="Pager">
</div>
<asp:TextBox ID="hfId" runat="server"></asp:TextBox>
<asp:TextBox ID="hfName" runat="server"></asp:TextBox>
<asp:TextBox ID="hfCountry" runat="server"></asp:TextBox>
<asp:TextBox ID="hfstream" runat="server"></asp:TextBox>
<asp:TextBox ID="hfTypes" runat="server"></asp:TextBox>
<asp:TextBox ID="hfProgram" runat="server"></asp:TextBox>
<asp:TextBox ID="hfLimit" runat="server"></asp:TextBox>
<asp:TextBox ID="hfHouse" runat="server"></asp:TextBox>
<asp:TextBox ID="hfRegno" runat="server"></asp:TextBox>
</form>
</body>
</html>
Imports System.Data
Imports System.Web.Services
Imports System.Data.SqlClient
Imports System.Configuration
Public Class StudentSearchnew
Inherits System.Web.UI.Page
Private Shared PageSize As Integer = 15
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
BindDummyRow()
End If
End Sub
Private Sub BindDummyRow()
Dim dummy As New DataTable()
dummy.Columns.Add("Account")
dummy.Columns.Add("Name")
dummy.Columns.Add("Class")
dummy.Columns.Add("Stream")
dummy.Columns.Add("Regno")
dummy.Columns.Add("STDTYPE")
dummy.Columns.Add("ACNOS")
dummy.Columns.Add("SEX")
dummy.Columns.Add("House")
dummy.Rows.Add()
gvCustomers.DataSource = dummy
gvCustomers.DataBind()
End Sub
Private Sub gvCustomers_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvCustomers.SelectedIndexChanged
End Sub
<WebMethod>
Public Shared Function GetCustomers(searchTerm As String, pageIndex As Integer) As String
Dim query As String = "[GetCustomers_Pager2000]"
Dim cmd As New SqlCommand(query)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@SearchTerm", searchTerm)
cmd.Parameters.AddWithValue("@PageIndex", pageIndex)
cmd.Parameters.AddWithValue("@PageSize", PageSize)
cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4).Direction = ParameterDirection.Output
Return GetData(cmd, pageIndex).GetXml()
End Function
Private Shared Function GetData(cmd As SqlCommand, pageIndex As Integer) As DataSet
Dim strConnString As String = ConfigurationManager.ConnectionStrings("STOREConnectionString").ConnectionString
Using con As New SqlConnection(strConnString)
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using ds As New DataSet()
sda.Fill(ds, "Customers")
Dim dt As New DataTable("Pager")
dt.Columns.Add("PageIndex")
dt.Columns.Add("PageSize")
dt.Columns.Add("RecordCount")
dt.Rows.Add()
dt.Rows(0)("PageIndex") = pageIndex
dt.Rows(0)("PageSize") = PageSize
dt.Rows(0)("RecordCount") = cmd.Parameters("@RecordCount").Value
ds.Tables.Add(dt)
Return ds
End Using
End Using
End Using
End Function
End Class
ALTER PROCEDURE [dbo].[GetCustomers_Pager2000]
@PageIndex INT = 1
,@PageSize INT = 20
,@RecordCount INT OUTPUT,
@SearchTerm nvarchar(200)
AS
BEGIN
SET NOCOUNT ON;
SELECT IDENTITY(INT,1,1) AS RowNumber
,[ADMNO]
,[Name]
,[Class]
,[Stream]
,[House]
,[STDTYPE]
,[SEX]
,[ACNOS]
INTO #Results
FROM [STUDENT]
WHERE ([Name] LIKE @SearchTerm or [Name] LIKE '%'+@SearchTerm+'%' or [Name] LIKE '%' + @SearchTerm or [Name] LIKE @SearchTerm + '%') OR @SearchTerm = ''
SELECT @RecordCount = COUNT(*)
FROM #Results
SELECT * FROM #Results
WHERE RowNumber BETWEEN(@PageIndex -1) * @PageSize + 1 AND(((@PageIndex -1) * @PageSize + 1) + @PageSize) - 1
DROP TABLE #Results
END