I am trying to get the selected gridview values to append the selected record values to the webpage page controls on the form please help
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Admin2.Master" CodeBehind="Payments.aspx.vb" Inherits="KABOJJACLASS.Payments" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link rel="stylesheet" href="../Scripts/Bootstrap3.3.3.min.css" />
<script type="text/javascript" src="../Scripts/Jquery1.9.1.min.js"></script>
<script type="text/javascript" src="../Scripts/Bootstrap 3.3.2.min.js"></script>
<script src="../Scripts/ASPSnippets_Pager.min.js"></script>
<script type="text/javascript">
function Showalert() {
alert('Call JavaScript function from codebehind');
}
</script>
<script type="text/javascript">
$(function () {
GetCustomers(1);
$("body").on("keyup", "[id*=txtSearch]", function () {
GetCustomers(parseInt(1));
});
$("body").on("click", ".Pager .page", function () {
GetCustomers(parseInt($(this).attr('page')));
});
});
function SearchTerm() {
return jQuery.trim($("[id*=txtSearch]").val());
};
function GetCustomers(pageIndex) {
$.ajax({
type: "POST",
url: "Payments.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);
}
var footer = $("[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("ADMNO").text());
$("td", row).eq(1).html($(this).find("Name").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("STATUS").text());
$("td", row).eq(5).html("<a href='javascript:;' onclick='GetData(this)'>Select</a>");
$("[id*=SearchGrid]").append(row);
row = $("[id*=SearchGrid] tr:last-child").clone(true);
});
$("[id*=SearchGrid]").append(footer);
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*=SearchGrid]").append(empty_row);
}
};
function GetData(ele) {
var row = $(ele).closest('tr');
var id = $("td", row).eq(0).html();
var name = $("td", row).eq(1).html();
var city = $("td", row).eq(2).html();
var country = $("td", row).eq(3).html();
var Sex = $("td", row).eq(4).html();
var Stats = $("td", row).eq(5).html();
$('[id*=hfId]').val(id);
$('[id*=lblId]').html(id);
$('[id*=txtName]').val(name);
$('[id*=ddlClass]').val(city);
$('[id*=txtCountry]').val(country);
$('[id*=txtCity]').val(Stats);
$('[id*=txtHouse]').val(House);
$('[id*=admno]').val(id);
}
</script>
<style type="text/css">
button,input,select,textarea{font-family:inherit;font-size:inherit;line-height:inherit}input{line-height:normal}button,input,optgroup,select,textarea{margin:0;font:inherit;color:inherit}*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}*,:after,:before{color:#000!important;text-shadow:none!important;background:0 0!important;-webkit-box-shadow:none!important;box-shadow:none!important}button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer}th{text-align:left}select{background:#fff!important}button,select{text-transform:none}
.auto-style4 {
width: 6px;
}
.auto-style6 {
width: 95%
}
.auto-style7 {
height: 20px;
}
.auto-style8 {
width: 6px;
height: 20px;
}
.auto-style9 {
width: 7px;
height: 20px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<asp:Panel ID="Panel3" runat="server">
<table class="auto-style1">
<tr>
<td>
<asp:Panel ID="Panel4" runat="server" Width="777px">
<table class="auto-style6">
<tr>
<td class="auto-style7" style="border: thin ridge #0000FF">Student Name</td>
<td class="auto-style7" style="border: thin ridge #0000FF">
<asp:Label ID="PatientName" runat="server" Text="Patient Name"></asp:Label>
</td>
<td class="auto-style8" style="border: thin ridge #0000FF">Admno</td>
<td class="auto-style8" style="border: thin ridge #0000FF">
<asp:Label ID="admno" runat="server"></asp:Label>
</td>
<td class="auto-style7" style="border: thin ridge #0000FF">Category</td>
<td class="auto-style7" style="border: thin ridge #0000FF">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>None</asp:ListItem>
<asp:ListItem>Saturday</asp:ListItem>
<asp:ListItem>Clubs</asp:ListItem>
<asp:ListItem>Trips</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="auto-style7" style="border: thin ridge #0000FF">Class</td>
<td class="auto-style7" style="border: thin ridge #0000FF">
<asp:Label ID="Classes" runat="server"></asp:Label>
</td>
<td class="auto-style7" style="border: thin ridge #0000FF">Stream</td>
<td class="auto-style7" style="border: thin ridge #0000FF">
<asp:Label ID="Stream" runat="server"></asp:Label>
</td>
<td class="auto-style9" style="border: thin ridge #0000FF"> </td>
<td class="auto-style9" style="border: thin ridge #0000FF"> </td>
</tr>
<tr>
<td style="border: thin ridge #0000FF">
<asp:Button ID="Button1" runat="server" OnClick="OnConfirm" Text="Save Payments" />
</td>
<td style="border: thin ridge #0000FF"> </td>
<td class="auto-style4" style="border: thin ridge #0000FF"> </td>
<td class="auto-style4" style="border: thin ridge #0000FF"> </td>
<td style="border: thin ridge #0000FF"> </td>
<td style="border: thin ridge #0000FF"> </td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td style="border: thin outset #0099CC">Student Search
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:GridView ID="SearchGrid" runat="server" AutoGenerateColumns="False" Height="214px" ItemStyle-Width="Auto" PageSize="25" ShowHeaderWhenEmpty="True" Width="1057px" ShowFooter="True">
<Columns>
<asp:TemplateField HeaderText="Admno">
<EditItemTemplate>
<asp:TextBox ID="txtadmno" runat="server" Text='<%# Bind("ADMNO") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbladmno" runat="server" Text='<%# Bind("ADMNO") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Name">
<EditItemTemplate>
<asp:TextBox ID="txtName0" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblContactName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Class">
<EditItemTemplate>
<asp:TextBox ID="txtCity0" runat="server" Text='<%# Bind("Class") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCity" runat="server" Text='<%# Bind("Class") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Stream">
<EditItemTemplate>
<asp:TextBox ID="txtCountry0" runat="server" Text='<%# Bind("Strean") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblCountry" runat="server" Text='<%# Bind("Stream") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Height="21px" Width="196px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Status") %>' Width="135px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="Staff" HeaderText="Select" Text="Select" />
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</asp:Panel>
</asp:Content>
Imports System.Data.SqlClient
Imports System.Data
Public Class Payments
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindDummyRow()
SearchGrid.DataBind()
End If
End Sub
Private Sub BindDummyRow()
Dim dummy As DataTable = New DataTable()
dummy.Columns.Add("ADMNO")
dummy.Columns.Add("Name")
dummy.Columns.Add("Class")
dummy.Columns.Add("Stream")
dummy.Columns.Add("sex")
dummy.Columns.Add("Status")
dummy.Columns.Add("studenttype")
'dummy.Columns.Add("RClass")
dummy.Rows.Add()
SearchGrid.DataSource = dummy
SearchGrid.DataBind()
'sample()
End Sub
Protected Sub OnConfirm(sender As Object, e As EventArgs) Handles Button1.Click
Dim message1 As String = "Are you Sure You Want To Post this Payment"
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "Confirm('" & message1 & "');", True)
End Sub
<System.Web.Services.WebMethod()>
Public Shared Function GetCustomers(ByVal searchTerm As String, ByVal pageIndex As Integer) As String
Dim query As String = "[GetCustomers_Pager2022]"
Dim cmd As SqlCommand = New SqlCommand(query)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@SearchTerm", searchTerm)
cmd.Parameters.AddWithValue("@PageIndex", pageIndex)
cmd.Parameters.AddWithValue("@PageSize", 25)
cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4).Direction = ParameterDirection.Output
Return GetData(cmd, pageIndex).GetXml()
End Function
Private Shared Function GetData(ByVal cmd As SqlCommand, ByVal pageIndex As Integer) As DataSet
Dim strConnString As String = ConfigurationManager.ConnectionStrings("SAT2022ConnectionString").ConnectionString
Using con As SqlConnection = New SqlConnection(strConnString)
Using sda As SqlDataAdapter = New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using ds As DataSet = New DataSet()
sda.Fill(ds, "Customers")
Dim dt As DataTable = 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") = 10
dt.Rows(0)("RecordCount") = cmd.Parameters("@RecordCount").Value
ds.Tables.Add(dt)
Return ds
End Using
End Using
End Using
End Function
Private Sub SearchGrid_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles SearchGrid.RowCommand
If e.CommandName = "Select" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = SearchGrid.Rows(index)
Dim admno As String = SearchGrid.Rows(index).Cells(0).Text
Dim namesd As String = SearchGrid.Rows(index).Cells(1).Text
Dim docment As String = SearchGrid.Rows(index).Cells(2).Text
' PatientNo.Text = admno
PatientName.Text = namesd
End If
End Sub
End Class
USE [SATCLASS]
GO
/****** Object: StoredProcedure [dbo].[GetCustomers_Pager2022] Script Date: 13/12/2023 07:53:20 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetCustomers_Pager2022]
@PageIndex INT = 1
,@PageSize INT = 50
,@RecordCount INT OUTPUT,
@SearchTerm nvarchar(200)
AS
BEGIN
SET NOCOUNT ON;
SELECT IDENTITY(INT,1,1) AS RowNumber
,[ADMNO]
,[Name]
,[Class]
,[Stream]
,[House]
,studenttype
,[STATUS]
,[SEX],Regno
INTO #Results
FROM P3P7
WHERE ([Name] LIKE @SearchTerm or [Name] LIKE '%'+@SearchTerm+'%' or [Name] LIKE '%' + @SearchTerm or [Name] LIKE @SearchTerm + '%') OR @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