Hi lingers,
Refer the sample.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}
table {
border: 1px solid #ccc;
}
table th {
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td {
padding: 5px;
border-color: #ccc;
}
.Pager span {
color: #333;
background-color: #F7F7F7;
font-weight: bold;
text-align: center;
display: inline-block;
width: 20px;
margin-right: 3px;
line-height: 150%;
border: 1px solid #ccc;
}
.Pager a {
text-align: center;
display: inline-block;
width: 20px;
border: 1px solid #ccc;
color: #fff;
color: #333;
margin-right: 3px;
line-height: 150%;
text-decoration: none;
}
</style>
<script type="text/javascript" src=" https://code.jquery.com/jquery-3.5.1.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css" />
<script type="text/javascript" src="https://cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="ASPSnippets_Pager.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
GetEmployees(parseInt(1));
var checked = [];
$('[id*=chkSelect]').on('click', function () {
if ($(this).is(":checked")) {
checked.push($(this).closest('tr').find('td').eq(1).html());
} else {
checked.pop($(this).closest('tr').find('td').eq(1).html());
}
$('[id*=hfCheckedIds]').val(checked.join(','));
});
});
$(document).on("click", '.Pager .page', function () {
GetEmployees(parseInt($(this).attr('page')));
});
var term = '';
$(document).on("keyup", 'input[type=search]', function () {
term = $(this).val();
GetEmployees(parseInt(1));
});
$(document).on("change", '[id*=ddlPageSize]', function () {
GetEmployees(parseInt(1));
});
function SearchTerm() {
return jQuery.trim($("input[type=search]").val());
};
$(document).on('click', '.view', function () {
var id = $(this).closest('tr').find('td').eq(1).html();
// Setting hidden field.
$('[id*=hfId]').val(id);
$.ajax({
type: "POST",
url: "CS.aspx/GetCustomersDetails",
data: '{empid: ' + id + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var job_material = xml.find("job_material");
var id = $(job_material[0]).find("EmployeeID").text();
var boardname = $(job_material[0]).find("FirstName").text();
var materialgsm = $(job_material[0]).find("LastName").text();
var materialcode = $(job_material[0]).find("City").text();
var materialwebwidth = $(job_material[0]).find("Country").text();
var costpersqmeter = $(job_material[0]).find("Address").text();
$('[id*=TextBox27]').val(boardname);
$('[id*=TextBox28]').val(materialgsm);
$('[id*=TextBox29]').val(materialcode);
$('[id*=TextBox30]').val(materialwebwidth);
$('[id*=TextBox31]').val(costpersqmeter);
ShowPopup();
},
error: function (response) {
alert(response.responseText);
}
});
return false;
});
var i = 0;
function GetEmployees(pageIndex) {
$.ajax({
type: "POST",
url: "CS.aspx/GetEmployees",
data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + ', pageSize: ' + $("[id*=ddlPageSize]").val() + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$('[id$=gvEmployees]').prepend($("<thead></thead>").append($('[id$=gvEmployees]').find("tr:first"))).DataTable().destroy();
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var Employees = xml.find("Employees");
var row = $("[id$=gvEmployees] tbody tr:last-child").eq(0).clone(true);
$("[id$=gvEmployees] tbody tr").not($("[id$=gvEmployees] tbody tr:first-child")).remove();
$.each(Employees, function () {
$("td", row).eq(1).html($(this).find("EmployeeID").text());
$("td", row).eq(2).html($(this).find("FirstName").text());
$("td", row).eq(3).html($(this).find("LastName").text());
$("td", row).eq(4).html($(this).find("Address").text());
$("td", row).eq(5).html($(this).find("City").text());
$("td", row).eq(6).html($(this).find("Country").text());
$("[id$=gvEmployees]").append(row);
row = $("[id$=gvEmployees] tbody tr:last-child").eq(0).clone(true);
});
$("[id$=gvEmployees] tbody tr:first-child").remove();
if (i != 0) {
$('[id$=gvEmployees]').DataTable({
"paging": false,
"info": false
});
} else {
$('[id$=gvEmployees]')
.prepend($("<thead></thead>").append($('[id$=gvEmployees]').find("tr:first")))
.DataTable({
"paging": false,
"info": false
});
}
if (term != '') {
$('input[type=search]').val(term);
}
$('input[type=search]').focus();
i++;
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())
});
},
error: function (response) {
alert(response.responseText);
}
});
}
function ShowPopup() {
$('#Label71').html('');
$("#dialog").dialog({
title: "VIEW CYLINDER DETAILS",
width: 830,
height: 500,
buttons: {
Close: function () {
$(this).dialog('close');
}
},
modal: true
});
$("#dialog").parent().appendTo($("form:first"));
};
function ShowPopup1() {
$('#Label71').html('');
$("#dialog1").dialog({
title: "EDIT CYLINDER DETAILS",
width: 830,
height: 500,
buttons: {
Close: function () {
$(this).dialog('close');
}
},
modal: true
});
$("#dialog1").parent().appendTo($("form:first"));
};
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<%--<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>--%>
<asp:HiddenField ID="hfCheckedIds" runat="server" />
<asp:HiddenField ID="hfId" runat="server" />
Page Size:
<asp:DropDownList runat="server" ID="ddlPageSize">
<asp:ListItem Text="1" Value="1" />
<asp:ListItem Text="5" Value="5" Selected="True" />
<asp:ListItem Text="10" Value="10" />
</asp:DropDownList>
<asp:GridView ID="gvEmployees" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID" Width="100%">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="EmployeeID" HeaderText="Id" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:BoundField DataField="Address" HeaderText="Address" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Country" HeaderText="Country" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button CssClass="view" Text="Unuseable" ID="Inkview" runat="server" ForeColor="white" BackColor="#FF6600" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<div class="Pager" style="width: 100%"></div>
<%--</ContentTemplate>
</asp:UpdatePanel>--%>
<div id="dialog" style="display: none">
<table align="center" border="2" font-size="xx-small">
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Button ID="Tab6" runat="server" BorderStyle="None" CssClass="Initial"
OnClick="Tab6_Click" Text="Manage Material" Width="151px" UseSubmitBehavior="false" Font-Bold="True" Font-Names="Arial Narrow" Font-Size="x-small" />
<asp:MultiView ID="MainView" runat="server">
<asp:View ID="View2" runat="server">
<table style="width: 100%; border-width: 1px; border-color: #666; border-style: solid">
<tr>
<td>
<p>
</p>
<p>
</p>
<table border="1" class="roundedCorners"
style="width: 100%; font-size: x-small; font-family: 'Arial Narrow'; font-weight: bold;">
<tr>
<td class="style32">Board Name</td>
<td class="style29">Gsm</td>
<td class="style33">Material Code</td>
<td class="style35">Web Width</td>
<td class="style35">Cost Per Kg</td>
</tr>
<tr>
<td class="style32">
<asp:TextBox ID="TextBox27" runat="server" Width="135px" Height="24px" Font-Size="x-Small"></asp:TextBox>
</td>
<td class="style29">
<asp:TextBox ID="TextBox28" runat="server" Width="135px" Height="24px" Font-Size="x-Small"></asp:TextBox>
</td>
<td class="style33">
<asp:TextBox ID="TextBox29" runat="server" Width="135px" Height="24px" Font-Size="x-Small"></asp:TextBox>
</td>
<td class="style35">
<asp:TextBox ID="TextBox30" runat="server" Width="135px" Height="24px" Font-Size="x-Small"></asp:TextBox>
</td>
<td class="style35">
<asp:TextBox ID="TextBox31" runat="server" Width="135px" Height="24px" Font-Size="x-Small"></asp:TextBox>
</td>
</tr>
</table>
<br />
<br />
<br />
<br />
</td>
</tr>
</table>
<asp:Button ID="Button2" runat="server" OnClick="Button1_Click" Height="34px" Width="142px"
Style="background: url(./Images/submit.jpg) no-repeat;" />
</asp:View>
</asp:MultiView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Tab6" EventName="click" />
<asp:AsyncPostBackTrigger ControlID="Button2" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</div>
<div id="dialog1" style="display: none">
<table align="center" border="2" font-size="xx-small">
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Button ID="Tab2" runat="server" BorderStyle="None" CssClass="Initial"
OnClick="Tab2_Click" Text=" Manage Material" Width="151px" UseSubmitBehavior="false" Font-Bold="True" Font-Names="Arial Narrow" Font-Size="x-small" />
<asp:MultiView ID="MainView1" runat="server">
<asp:View ID="View1" runat="server">
<table style="width: 100%; border-width: 1px; border-color: #666; border-style: solid">
<tr>
<td align="center">
<asp:Label ID="Label71" runat="server" Width="400px" ForeColor="White" BackColor="#339966" Visible="False"></asp:Label>
<p align="center">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Height="34px" Width="142px"
Style="background: url(./Images/submit.jpg) no-repeat;" />
</p>
<p>
</p>
<table border="1" class="roundedCorners" align="center"
style="width: 100%; font-size: x-small; font-family: 'Arial Narrow'; font-weight: bold;">
<tr>
<td class="style32">Board Name</td>
<td class="style29">Gsm</td>
<td class="style33">Material Code</td>
<td class="style35">Web Width</td>
<td class="style35">Cost Per Kg</td>
</tr>
<tr>
<td class="style32">
<asp:TextBox ID="TextBox1" runat="server" Width="135px" Height="24px" Font-Size="x-Small"></asp:TextBox>
</td>
<td class="style29">
<asp:TextBox ID="TextBox2" runat="server" Width="135px" Height="24px" Font-Size="x-Small"></asp:TextBox>
</td>
<td class="style33">
<asp:TextBox ID="TextBox3" runat="server" Width="135px" Height="24px" Font-Size="x-Small"></asp:TextBox>
</td>
<td class="style35">
<asp:TextBox ID="TextBox4" runat="server" Width="135px" Height="24px" Font-Size="x-Small"></asp:TextBox>
</td>
<td class="style35">
<asp:TextBox ID="TextBox5" runat="server" Width="135px" Height="24px" Font-Size="x-Small"></asp:TextBox>
</td>
</tr>
</table>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label" Visible="False"></asp:Label>
</td>
</tr>
</table>
</asp:View>
</asp:MultiView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Tab6" EventName="click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</div>
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
GetEmployees(1);
}
});
};
</script>
</form>
</body>
</html>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDummyRow();
}
MainView.ActiveViewIndex = 0;
MainView1.ActiveViewIndex = 0;
}
private void BindDummyRow()
{
DataTable dummy = new DataTable();
dummy.Columns.Add("EmployeeID");
dummy.Columns.Add("FirstName");
dummy.Columns.Add("LastName");
dummy.Columns.Add("Address");
dummy.Columns.Add("City");
dummy.Columns.Add("Country");
dummy.Rows.Add();
gvEmployees.DataSource = dummy;
gvEmployees.DataBind();
}
protected void Tab6_Click(object sender, EventArgs e)
{
Label71.Visible = false;
Tab6.CssClass = "Clicked";
MainView.ActiveViewIndex = 0;
gvEmployees.UseAccessibleHeader = true;
gvEmployees.HeaderRow.TableSection = TableRowSection.TableHeader;
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup()", true);
}
protected void Tab2_Click(object sender, EventArgs e)
{
Label71.Visible = false;
Tab2.CssClass = "Clicked";
MainView1.ActiveViewIndex = 0;
gvEmployees.UseAccessibleHeader = true;
gvEmployees.HeaderRow.TableSection = TableRowSection.TableHeader;
ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup1()", true);
}
[WebMethod]
public static string GetEmployees(int pageIndex, string searchTerm, int pageSize)
{
string query = "[Employees_GetEmployeesPageWise]";
SqlCommand cmd = 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, pageSize).GetXml();
}
[WebMethod]
public static string GetCustomersDetails(int empid)
{
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Employees WHERE employeeid = @id"))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@id", empid);
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds, "job_material");
return ds.GetXml();
}
}
}
}
}
private static DataSet GetData(SqlCommand cmd, int pageIndex, int pageSize)
{
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds, "Employees");
DataTable dt = 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;
}
}
}
}
protected void Button1_Click(object sender, object e)
{
Label71.Visible = false;
int id = 0;
int.TryParse(hfId.Value, out id);
Session["DatakeyValue"] = id;
}
Screenshot