Grid view not displaying data. I created a 11column gridview with the example you taught me. While the example below worked, the gridview with 11 column did not work.
This example you gave me code works perfectly well but this one does not display anything, because i have 11 column as against four column in the example you gave me.
It is not displaying anything, do i need to alter the procedure or code behind.
Please help.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default29.aspx.cs" Inherits="Default29" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>VIEW /EDIT JOB</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.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>
<script src="JS/ASPSnippets_Pager.min.js"></script>
<script type="text/javascript">
$(function () {
GetCustomers(1);
});
$(".Pager .page").live("click", function () {
GetCustomers(parseInt($(this).attr('page')));
});
var i = 0;
function GetCustomers(pageIndex) {
$.ajax({
type: "POST",
url: "Default29.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");
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(1).html($(this).find("id").text());
$("td", row).eq(2).html($(this).find("pid").text());
$("td", row).eq(3).html($(this).find("variant").text());
$("td", row).eq(4).html($(this).find("Country").text());
$("td", row).eq(5).html($(this).find("pack").text());
$("td", row).eq(6).html($(this).find("customer").text());
$("td", row).eq(7).html($(this).find("jobnumber").text());
$("td", row).eq(8).html($(this).find("artworkdate").text());
$("td", row).eq(9).html($(this).find("reprodate").text());
$("td", row).eq(10).html($(this).find("artworknumber").text());
$("td", row).eq(11).html($(this).find("templateno").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" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.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" />
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js"></script>
<script type="text/javascript" src=" https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></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;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#3366CC" BorderStyle="None"
Font-Names="Century Gothic" Font-Size="XX-Small" DataKeyNames="id"
Width="100%" Style="margin-bottom: 0px" CssClass="grid">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="id" />
<asp:BoundField DataField="pid" HeaderText="pid" />
<asp:BoundField DataField="variant" HeaderText="variant" />
<asp:BoundField DataField="country" HeaderText="country" />
<asp:BoundField DataField="pack" HeaderText="pack" />
<asp:BoundField DataField="customer" HeaderText="customer" />
<asp:BoundField DataField="jobnumber" HeaderText="jobnumber" />
<asp:BoundField DataField="artworkdate" HeaderText="artworkdate" />
<asp:BoundField DataField="reprodate" HeaderText="reprodate" />
<asp:BoundField DataField="artworknumber" HeaderText="artworknumber" />
<asp:BoundField DataField="templateno" HeaderText="templateno" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button Text="View" ID="Inkview" runat="server" ForeColor="white" BackColor="#FF6600" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button Text="Edit" ID="lnkView1" runat="server" ForeColor="white" BackColor="#FF6600" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BackColor="green" Font-Bold="True" ForeColor="#CCCCFF" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyle BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderStyle BackColor="#002876" />
</asp:GridView>
<br />
<div class="Pager" style="width: 100%"></div>
</div>
</form>
</body>
</html>
public partial class Default29 : System.Web.UI.Page
{
private static int PageSize = 15;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDummyRow();
}
}
private void BindDummyRow()
{
DataTable dummy = new DataTable();
dummy.Columns.Add("id");
dummy.Columns.Add("pid");
dummy.Columns.Add("variant");
dummy.Columns.Add("Country");
dummy.Columns.Add("pack");
dummy.Columns.Add("customer");
dummy.Columns.Add("jobnumber");
dummy.Columns.Add("artworkdate");
dummy.Columns.Add("reprodate");
dummy.Columns.Add("artworknumber");
dummy.Columns.Add("templateno");
dummy.Rows.Add();
gvDetails.DataSource = dummy;
gvDetails.DataBind();
//gvDetails.UseAccessibleHeader = true;
//gvDetails.HeaderRow.TableSection = TableRowSection.TableHeader;
}
[WebMethod]
public static string GetCustomers(int pageIndex)
{
string query = "[Prepress]";
SqlCommand cmd = new SqlCommand(query);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
cmd.Parameters.AddWithValue("@PageSize", PageSize);
cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
return GetData(cmd, pageIndex).GetXml();
}
private static DataSet GetData(SqlCommand cmd, int pageIndex)
{
string strConnString = ConfigurationManager.ConnectionStrings["conString"].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, "job");
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;
}
}
}
}
}