Please help before clicking on the search facility the modal popup works well but after searching for a particular record the modal shows different record please help
Code:
Imports System.Data.SqlClient
Imports System.Data
Public Class Student
Inherits System.Web.UI.Page
Dim constr As String = ConfigurationManager.ConnectionStrings("UNIFORMConnectionString").ConnectionString
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim constr As String = ConfigurationManager.ConnectionStrings("UNIFORMConnectionString").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("SELECT*FROM Student", con)
Using sda As New SqlDataAdapter(cmd)
cmd.CommandType = CommandType.Text
Dim dt As New DataTable()
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
GridView1.UseAccessibleHeader = True
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader
End Using
End Using
End Using
' [Date].Text = Convert.ToDateTime(DateAndTime.Now).ToString("dd/MM/yyyy")
[Date].Text = DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt")
' Dim name As String = Streamddl.SelectedItem.Text
End If
End Sub
Protected Sub OnUpdate(ByVal sender As Object, ByVal e As EventArgs)
' Code to update the record.
Dim id As String = Request.Form("txtId")
Dim name As String = Request.Form("txtName")
Dim country As String = Request.Form("txtCountry")
Dim categoryad As String = Request.Form("admno")
' Categorym.Text = Request.Form("Categoryddl")
' Names.Text = name
' Countrys.Text = country
Streamddl.SelectedItem.Value = Request.Form("Streamddl")
Using Cont As New SqlConnection(constr)
Cont.Open()
Using cmd As New SqlCommand
cmd.Connection = Cont
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "Pushpay"
cmd.Parameters.Add("@a", SqlDbType.NVarChar).Value = admno.Text
cmd.Parameters.Add("@n", SqlDbType.NVarChar).Value = txtName.Text
cmd.Parameters.Add("@c", SqlDbType.NVarChar).Value = txtCountry.Text
cmd.Parameters.Add("@s", SqlDbType.NVarChar).Value = Streamddl.SelectedItem.Text
cmd.Parameters.Add("@d", SqlDbType.DateTime).Value = [Date].Text
cmd.Parameters.Add("@cs", SqlDbType.NVarChar).Value = Pay.Text
cmd.Parameters.Add("@t", SqlDbType.NVarChar).Value = Termdll.SelectedItem.Text
cmd.Parameters.Add("@ct", SqlDbType.NVarChar).Value = Categoryddl.SelectedItem.Text
cmd.ExecuteReader()
Cont.Close()
End Using
End Using
ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "showalert", "alert('Record Saved Successfully');window.location ='" + Request.Url.AbsoluteUri + "';", True)
GridView1.UseAccessibleHeader = True
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader
End Sub
Protected Sub OnUpdate2000(ByVal sender As Object, ByVal e As EventArgs) Handles Streamddl.SelectedIndexChanged
' Code to update the record.
Dim id As String = admno.Text
Dim name As String = Streamddl.SelectedItem.Text
Dim country As String = Request.Form("txtCountry")
Dim categoryad As String = Request.Form("admno")
End Sub
End Class
Code:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Forms/Site1.Master" CodeBehind="Student.aspx.vb" Inherits="UNIFORMSWEBAPP.Student" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.auto-style3 {
width: 817px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<table class="auto-style4">
<tr>
<td class="auto-style3"> </td>
<td> </td>
</tr>
<tr>
<td class="auto-style3">
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
.auto-style4 {
width: 1058px;
}
</style>
<div>
</div>
<div class="container">
<div class="table-responsive">
<asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server"
CssClass="table table-bordered table-hover table-striped thead-dark GridCustomers" Height="148px" style="font-size: small" Width="1050px">
<Columns>
<asp:BoundField DataField="admno" HeaderText="admno" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Class" HeaderText="Class" />
<asp:BoundField DataField="Stream" HeaderText="Stream" />
<asp:BoundField DataField="House" HeaderText="House" />
<asp:BoundField DataField="Sex" HeaderText="Sex" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" href="#" data-target="#MyPopup" data-toggle="modal"
runat="server">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</div>
<div id="MyPopup" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
×</button>
<h4 class="modal-title">
Update Payments
</h4>
</div>
<div class="modal-body">
<table class="table table-bordered table-hover table-striped thead-dark">
<tr>
<td>
admno
</td>
<td>
<asp:TextBox runat="server" ID="admno" CssClass="form-control" />
</td>
</tr>
<tr>
<td>
Name
</td>
<td>
<asp:TextBox runat="server" ID="txtName" CssClass="form-control" />
</td>
</tr>
<tr>
<td>
Class
</td>
<td>
<asp:TextBox runat="server" ID="txtCountry" CssClass="form-control" />
</td>
</tr>
<tr>
<td>
Stream
</td>
<td>
<asp:DropDownList ID="Streamddl" runat="server" DataSourceID="SqlDataSource2" DataTextField="stream" DataValueField="stream" CssClass="dropdown" AutoPostBack="true" OnSelectedIndexChanged="OnUpdate2000" >
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:UNIFORMConnectionString %>" SelectCommand="SELECT * FROM [streamdata]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
Date
</td>
<td>
<asp:TextBox runat="server" ID="Date" CssClass="form-control" />
</td>
</tr>
<tr>
<td>
Cash
</td>
<td>
<asp:TextBox runat="server" ID="Pay" CssClass="form-control" />
</td>
</tr>
<tr>
<td>
Term
</td>
<td>
<asp:DropDownList ID="Termdll" runat="server" CssClass="form-control">
<asp:ListItem>NONE</asp:ListItem>
<asp:ListItem>TERMI</asp:ListItem>
<asp:ListItem>TERMII</asp:ListItem>
<asp:ListItem>TERMIII</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Category
</td>
<td>
<asp:DropDownList ID="Categoryddl" runat="server" CssClass="form-control">
<asp:ListItem>NONE</asp:ListItem>
<asp:ListItem>SATURDAY</asp:ListItem>
<asp:ListItem>CLUBS</asp:ListItem>
<asp:ListItem>TRIPS</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</div>
<div class="modal-footer">
<asp:Button ID="btnUpdate" Text="Update" runat="server" CssClass="btn btn-primary"
OnClick="OnUpdate" />
<input type="button" value="Close" class="btn btn-danger" data-dismiss="modal" />
</div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css" rel="stylesheet"
type="text/css" />
<script type="text/javascript">
$(function () {
$(".GridCustomers").DataTable({
bLengthChange: true,
lengthMenu: [[10, 15, -1], [10, 15, "All"]],
bFilter: true,
bSort: true,
bPaginate: true
});
$("[id*=lnkEdit]").click(function () {
$('[id*=admno]').val($(this).closest('tr').find('td').eq(0).html());
$('[id*=txtName]').val($(this).closest('tr').find('td').eq(1).html());
$('[id*=txtCountry]').val($(this).closest('tr').find('td').eq(2).html());
$('[id*=Streamddl]').val($(this).closest('tr').find('td').eq(3).html());
$('#MyPopup').modal('show');
return false;
});
});
</script>
</td>
</tr>
<tr>
<td class="auto-style3">
</td>
<td> </td>
</tr>
</table>
</asp:Content>