Please help after using the selected index the populated values can to remain on the webpage they instead disappear yet i wanted to use them
How can i maintain the selected values and pass them using command button 2
Imports System.IO
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Public Class SearchsingleReports
Inherits System.Web.UI.Page
Dim constr As String = ConfigurationManager.ConnectionStrings("SMIS2022ConnectionString").ConnectionString
Private Shared PageSize As Integer = 25
Dim classrk, streamk, rset As String
Dim startTime As DateTime
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
classrk = Session("Class").ToString()
streamk = Session("Stream").ToString()
startTime = CType(Session("From"), DateTime)
rset = Session("Transmission").ToString()
SetName.Text = Session("Category").ToString()
Classn.Text = Session("Class").ToString()
Setdata.Text = Session("Transmission").ToString()
Datedata.Text = startTime
Streamd.Text = streamk
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("House")
'dummy.Columns.Add("RClass")
dummy.Rows.Add()
SearchGrid.DataSource = dummy
SearchGrid.DataBind()
'sample()
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
Protected Sub SearchGrid_SelectedIndexChanged(sender As Object, e As EventArgs) Handles SearchGrid.SelectedIndexChanged
Dim admno As String = hfId.Value
Dim Classr As String = hfclass.Value
End Sub
Private Shared Function GetData(ByVal cmd As SqlCommand, ByVal pageIndex As Integer) As DataSet
Dim strConnString As String = ConfigurationManager.ConnectionStrings("SMIS2022ConnectionString").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
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Response.Redirect(String.Format("~/MenuAcademics.aspx"))
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "askConfirmk", "alert('" & admn.Text & " ... !!')", True)
End Sub
End Class
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="../Scripts/jquery-1.8.3.min.js"></script>
<script src="../Scripts/ASPSnippets_Pager.min.js"></script>
<title></title>
</head>
<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: "SearchUploadPhoto.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("SEX").text());
$("td", row).eq(7).html($(this).find("STATUS").text());
$("td", row).eq(5).html($(this).find("studenttype").text());
$("td", row).eq(6).html($(this).find("House").text());
$("td", row).eq(8).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 classr = $("td", row).eq(2).html();
var streamr = $("td", row).eq(3).html();
$('[id*=hfId]').val(id);
$('[id*=lblId]').html(id);
$('[id*=Namesdata]').val(name);
$('[id*=admn]').val(id);
$('[id*=Classstream]').val(classr + streamr);
$('[id*=hfName]').val(name);
$('[id*=hfclass]').val(classr);
}
</script>
<script type="text/javascript">
function askConfirm(msg) {
alert(msg)
}
</script>
<body style="background-color: #66CCFF">
<form id="form1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" />
<table class="auto-style8">
<tr>
<td>
<asp:Label ID="Classn" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:Label ID="Streamd" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:Label ID="Setdata" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:Label ID="SetName" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:Label ID="Datedata" runat="server" Text="Label"></asp:Label>
</td>
<td class="auto-style9">
<asp:DropDownList ID="Classes0" runat="server" AutoPostBack="True" DataSourceID="rclass" DataTextField="CLASS" DataValueField="CLASS" Height="25px" Width="70px">
</asp:DropDownList>
<asp:SqlDataSource ID="rclass" runat="server" ConnectionString="<%$ ConnectionStrings:SMIS2022ConnectionString %>" SelectCommand="SELECT [CLASS] FROM [CLASS]"></asp:SqlDataSource>
</td>
</tr>
</table>
<hr />
<asp:Panel ID="Panel1" runat="server" BorderStyle="Double" Width="941px" Height="27px">
<table class="auto-style10">
<tr>
<td class="auto-style5">Search</td>
<td class="auto-style5">
<asp:TextBox ID="txtSearch" runat="server" Width="92px"></asp:TextBox>
</td>
<td class="auto-style6">Admno</td>
<td class="auto-style6">
<asp:TextBox ID="admn" runat="server" Width="111px" ReadOnly="True"></asp:TextBox>
</td>
<td class="auto-style4">Name</td>
<td class="auto-style7">
<asp:TextBox ID="Namesdata" runat="server" Width="160px" ReadOnly="True"></asp:TextBox>
</td>
<td class="auto-style3">Class</td>
<td class="auto-style3">
<asp:TextBox ID="Classstream" runat="server" Width="79px" ReadOnly="True"></asp:TextBox>
</td>
<td class="auto-style3">
<asp:Button ID="Button2" runat="server" Text="Extract Report" />
</td>
<td class="auto-style3">
<asp:Button ID="Button1" runat="server" Text="Back To Menu" />
</td>
</tr>
</table>
</asp:Panel>
<asp:TextBox ID="admn0" runat="server" Width="111px" ReadOnly="True" Visible="False"></asp:TextBox>
<br />
<table class="auto-style2">
<tr>
<td>
<asp:GridView ID="SearchGrid" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="SearchGrid_SelectedIndexChanged">
<Columns>
<asp:TemplateField HeaderText="ADMNO">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ADMNO") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ADMNO") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Name">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Class">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Class") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("Class") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Stream">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Stream") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Stream") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sex">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("Sex") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Sex") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Type">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("studenttype") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("studenttype") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Colour">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("House") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("House") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<EditItemTemplate>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("STATUS") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Bind("STATUS") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="Select" HeaderText="Select" Text="Select" />
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td></td>
</tr>
</table>
<table class="ui-accordion">
<tr>
<td>
<asp:TextBox ID="Names" runat="server" Width="167px"></asp:TextBox>
</td>
</tr>
</table>
<asp:HiddenField ID="hfId" runat="server" />
<asp:HiddenField ID="hfName" runat="server" />
<asp:HiddenField ID="hfclass" runat="server" />
<asp:HiddenField ID="hfstream" runat="server" />
</form>
</body>
</html>