Hi lingers,
Place the HiddenField in other TemplateField and remove the 1st TemplateField column.
Then set the HiddenField with id using jQuery in the row.
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<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 () {
GetCustomers(1);
});
$(document).on("click", '.Pager .page', function () {
GetCustomers(parseInt($(this).attr('page')));
});
$(document).on('click', '.view', function () {
$('[id*=hfId]').val($(this).closest('tr').find('td').eq(0).html());
});
var i = 0;
function GetCustomers(pageIndex) {
$.ajax({
type: "POST",
url: "Material.aspx/GetCustomers",
data: '{pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$('[id$=gvDetails]').prepend($("<thead></thead>").append($('[id$=gvDetails]').find("tr:first"))).DataTable().destroy();
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var customers = xml.find("job_material");
var row = $("[id$=gvDetails] tbody tr:last-child").eq(0).clone(true);
$("[id$=gvDetails] tbody tr").not($("[id$=gvDetails] tbody tr:first-child")).remove();
$.each(customers, function () {
$("td", row).eq(0).html($(this).find("boardname").text());
$("td", row).eq(1).html($(this).find("materialgsm").text());
$("td", row).eq(2).html($(this).find("materialcode").text());
$("td", row).eq(3).html($(this).find("materialwebwidth").text());
$("td", row).eq(4).html($(this).find("costpersqmeter").text());
$("td", row).find('[id*=id]').val($(this).find("id").text());
$("[id$=gvDetails]").append(row);
row = $("[id$=gvDetails] tbody tr:last-child").eq(0).clone(true);
});
$("[id$=gvDetails] tbody tr:first-child").remove();
if (i != 0) {
$('[id$=gvDetails]').DataTable({
"paging": false,
"info": false
});
} else {
$('[id$=gvDetails]')
.prepend($("<thead></thead>").append($('[id$=gvDetails]').find("tr:first")))
.DataTable({
"paging": false,
"info": false
});
}
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())
});
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
}
</script>
<script type="text/javascript">
function ShowPopup() {
$('#label71').html('');
$("#dialog").dialog({
title: "VIEW MATERIAL DETAILS",
width: 830,
height: 300,
buttons: {
Close: function () {
$(this).dialog('close');
}
},
modal: true
});
$("#dialog").parent().appendTo($("form:first"));
};
function ShowPopup1() {
$('#label71').html('');
$("#dialog1").dialog({
title: "EDIT MATERIAL DETAILS",
width: 830,
height: 300,
buttons: {
Close: function () {
$(this).dialog('close');
}
},
modal: true
});
$("#dialog1").parent().appendTo($("form:first"));
};
</script>
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}
.Pager span {
text-align: center;
color: #999;
display: inline-block;
width: 20px;
background-color: #A1DCF2;
margin-right: 3px;
line-height: 150%;
border: 1px solid #3AC0F2;
}
.Pager a {
text-align: center;
display: inline-block;
width: 20px;
background-color: #3AC0F2;
color: #fff;
border: 1px solid #3AC0F2;
margin-right: 3px;
line-height: 150%;
text-decoration: none;
}
.style102 {
width: 106px;
}
</style>
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None"
Font-Names="Century Gothic" Font-Size="X-Small" DataKeyNames="id"
Width="100%" Style="margin-bottom: 0px" CssClass="grid" BorderWidth="1px" CellPadding="3">
<Columns>
<asp:BoundField DataField="boardname" HeaderText="Boardname" />
<asp:BoundField DataField="materialgsm" HeaderText="GSM" />
<asp:BoundField DataField="materialcode" HeaderText="Material Code" />
<asp:BoundField DataField="materialwebwidth" HeaderText="Web Width" />
<asp:BoundField DataField="costpersqmeter" HeaderText="Cost Per Square Meter" />
<asp:TemplateField>
<ItemTemplate>
<asp:HiddenField ID="id" runat="server" Value='<%#Eval("id") %>' />
<asp:Button CssClass="view" Text="View" ID="Inkview" runat="server" OnClick="Inkview_Click" ForeColor="white" BackColor="#FF6600" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button CssClass="view" Text="Edit" ID="lnkView1" runat="server" OnClick="Inkview_Click1" ForeColor="white" BackColor="#FF6600" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#7EA9D3" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000000" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="#000000" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
<br />
<div class="Pager" style="width: 100%"></div>