makumbi says:
<
asp:BoundField
HeaderStyle-Width
=
"150px"
DataField
=
"Name"
HeaderText
=
"Name"
ItemStyle-CssClass
=
"ContactName"
>
<
HeaderStyle
Width
=
"150px"
></
HeaderStyle
>
<
ItemStyle
CssClass
=
"ContactName"
></
ItemStyle
>
You had set the ItemStyle-CssClass as ContactName.
makumbi says:
$(".Name").each(function () {
var searchPattern = new RegExp('(' + SearchTerm() + ')', 'ig');
$(this).html($(this).text().replace(searchPattern, "<
span
class
=
'highlight'
>" + SearchTerm() + "</
span
>"));
});
But in jQuery you are selecting with Name. So you need to change either ItemStyle-CssClass or jQuery selector.
Also remove the duplicate JavaScript code.
Refer the updated code.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="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: "Find.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("Regno").text());
$("td", row).eq(5).html($(this).find("Program").text());
$("td", row).eq(6).html($(this).find("Limit").text());
$("td", row).eq(7).html($(this).find("Type").text());
$("td", row).eq(8).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())
});
$(".Name").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 account = 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(7).html();
var Program = row.find("td").eq(5).html();
var Limit = row.find("td").eq(6).html();
var House = row.find("td").eq(8).html();
var Regno = row.find("td").eq(4).html();
document.getElementById("hfId").value = account;
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>
<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="Name" HeaderText="Name"
ItemStyle-CssClass="Name">
<HeaderStyle Width="150px"></HeaderStyle>
<ItemStyle CssClass="Name"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderStyle-Width="150px" DataField="Account" HeaderText="Account">
<HeaderStyle Width="150px"></HeaderStyle>
</asp:BoundField>
<asp:BoundField HeaderStyle-Width="150px" DataField="Class" HeaderText="Class">
<HeaderStyle Width="150px"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="Stream" HeaderText="Stream" />
<asp:BoundField DataField="Regno" HeaderText="Regno" />
<asp:BoundField DataField="Program" HeaderText="Program" />
<asp:BoundField DataField="Limit" HeaderText="BookLimit" />
<asp:BoundField DataField="Type" HeaderText="Type" />
<asp:BoundField DataField="House" HeaderText="House" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
<br />
<div class="Pager">
</div>
<asp:HiddenField ID="hfId" runat="server"></asp:HiddenField>
<asp:HiddenField ID="hfName" runat="server"></asp:HiddenField>
<asp:HiddenField ID="hfCountry" runat="server"></asp:HiddenField>
<asp:HiddenField ID="hfstream" runat="server"></asp:HiddenField>
<asp:HiddenField ID="hfTypes" runat="server"></asp:HiddenField>
<asp:HiddenField ID="hfProgram" runat="server"></asp:HiddenField>
<asp:HiddenField ID="hfLimit" runat="server"></asp:HiddenField>
<asp:HiddenField ID="hfHouse" runat="server"></asp:HiddenField>
<asp:HiddenField ID="hfRegno" runat="server"></asp:HiddenField>
<asp:Label ID="Usernames" runat="server" Text="Usernames"></asp:Label>
</form>
</body>
</html>
Code
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("Program")
dummy.Columns.Add("Limit")
dummy.Columns.Add("Type")
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
Dim account As String = hfName.Value
Dim names As String = hfId.Value
Dim classs As String = hfCountry.Value
Dim streams As String = hfstream.Value
Dim types As String = hfTypes.Value
Dim program As String = hfProgram.Value
Dim regno As String = hfRegno.Value
Dim bklimit As String = hfLimit.Value
Dim house As String = hfHouse.Value
Dim username As String = Usernames.Text
Response.Redirect(String.Format("Libraryorders.aspx?account={0}&names={1}&class={2}&stream={3}&types={4}&program={5}&Regno={6}&booklimit={7}&house={8}&username={9}", account, names, classs, streams, types, program, regno, bklimit, house, username))
End Sub
Private Sub VB_LoadComplete(sender As Object, e As EventArgs) Handles Me.LoadComplete
Usernames.Text = Request.QueryString("username")
'hfName.Visible = False
' hfId.Visible = False
' hfCountry.Visible = False
' hfstream.Visible = False
' hfTypes.Visible = False
' hfProgram.Visible = False
' hfRegno.Visible = False
' hfLimit.Visible = False
' hfHouse.Visible = False
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("SLISConnectionString").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