Please help select button returns empty values yet there is data in the gridview please help
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Searchitems.aspx.vb" Inherits="UNIFORMWEB2023.Searchitems" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="../Scripts/jquery-1.8.3.min.js"></script>
<script src="ASPSnippets_Pager.min.js"></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: "Searchitems.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*=SearchGrid] tr:last-child").clone(true);
}
$("[id*=SearchGrid] tr").not($("[id*=SearchGrid] tr:first-child")).remove();
if (customers.length > 0) {
$.each(customers, function () {
var customer = $(this);
$("td", row).eq(0).html($(this).find("itemcode").text());
$("td", row).eq(1).html($(this).find("stockitem").text());
$("td", row).eq(2).html($(this).find("itemsize").text());
$("td", row).eq(3).html($(this).find("Colour").text());
$("td", row).eq(4).html($(this).find("costprice").text());
$("td", row).eq(5).html($(this).find("saleprice").text());
$("[id*=SearchGrid]").append(row);
row = $("[id*=SearchGrid] 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())
});
$(".stockitem").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*=SearchGrid]").append(empty_row);
}
};
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style2">Search Item</td>
<td>
<asp:TextBox ID="txtSearch" runat="server" style="margin-left: 0px"></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="SearchGrid" runat="server" AutoGenerateColumns="False" ItemStyle-Width="Auto" PageSize="25">
<Columns>
<asp:TemplateField HeaderText="Itemcode">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("itemcode") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="itemcode" runat="server" Text='<%# Eval("itemcode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Stockitem">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("stockitem") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="stockitem" runat="server" Text='<%# Bind("stockitem") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="itemsize">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("itemsize") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="itemsize" runat="server" Text='<%# Bind("itemsize") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Colour">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Colour") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="colour" runat="server" Text='<%# Bind("Colour") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Costprice">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Costprice") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Costprice" runat="server" Text='<%# Bind("Costprice") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SalePrice">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Saleprice") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Saleprice" runat="server" Text='<%# Bind("Saleprice") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="Staff" HeaderText="Select" Text="Select" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Private Sub SearchGrid_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles SearchGrid.RowCommand
If e.CommandName = "Staff" Then
Try
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = SearchGrid.Rows(index)
Dim itemcode As String = DirectCast(SearchGrid.Rows(index).Cells(1).FindControl("itemcodex"), TextBox).Text
Dim stockitem As String = DirectCast(SearchGrid.Rows(index).Cells(2).FindControl("stockitem"), Label).Text
Dim colour As String = DirectCast(SearchGrid.Rows(index).Cells(3).FindControl("colour"), Label).Text
Dim itemsize As String = DirectCast(SearchGrid.Rows(index).Cells(4).FindControl("itemsize"), Label).Text
Dim dt As DataTable = DirectCast(Session("Customers"), DataTable)
dt.Rows.Add(itemcode, stockitem, colour, itemsize)
Session("Customers") = dt
Response.Redirect(String.Format("~/Forms/Shopentryform.aspx"))
Catch ex As Exception
End Try
End If