When i select the record after record search it flags this error please help
Unhandled exception at line 445, column 13 in http://localhost:1157/FormsV2/Find.aspx
0x800a138f - JavaScript runtime error: Unable to set property 'value' of undefined or null reference
document.getElementById("hfId").value = customerid;
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="Find.aspx.vb" Inherits="SLISWEB2023.Find1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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: "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())
});
$(".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);
}
};
</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 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(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 = 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>
<body>
Search:
<asp:TextBox ID="txtSearch" runat="server" />
<hr />
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="False" Height="16px" Width="855px">
<Columns>
<asp:BoundField HeaderStyle-Width="150px" DataField="Name" HeaderText="Name"
ItemStyle-CssClass="ContactName" >
<HeaderStyle Width="150px"></HeaderStyle>
<ItemStyle CssClass="ContactName"></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>
</body>
</html>
</asp:Content>
Imports System.Data
Imports System.Web.Services
Imports System.Data.SqlClient
Imports System.Configuration
Public Class Find1
Inherits System.Web.UI.Page
Dim conString As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
Private Shared PageSize As Integer = 15
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.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
<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
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
Using Con As New SqlConnection(conString)
Con.Open()
Using Com2 As New SqlCommand("update ledger Set dout= DATEDIFF(d, DueDate, GETDATE()) WHERE(category Is NULL) and account= '" & account & "'", Con)
Using RDR2 = Com2.ExecuteReader()
End Using
End Using
End Using
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 gvCustomers_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvCustomers.RowCommand
If e.CommandName = "Select" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = gvCustomers.Rows(index)
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
Session("account") = account
Session("Names") = names
Session("Class") = classs
Session("Stream") = streams
Session("types") = types
Session("Program") = program
Session("regno") = regno
Session("bklimit") = bklimit
Session("House") = house
Session("Username") = username
Using Con As New SqlConnection(conString)
Con.Open()
Using Com2 As New SqlCommand("update ledger Set dout= DATEDIFF(d, DueDate, GETDATE()) WHERE(category Is NULL) and account= '" & account & "'", Con)
Using RDR2 = Com2.ExecuteReader()
End Using
End Using
End Using
Response.Redirect(String.Format("~/FormsV2/LibraryordersV2.aspx"))
End If
End Sub
End Class