这是我的aspx代码:
<asp:GridView ID="GridView1" Font-Size = "11pt" OnRowCommand="GridView1_RowCommand" AllowPaging="true" AllowSorting="true" PagerSettings-Visible="true" PageSize="4" CssClass="footable" runat="server" AutoGenerateColumns="false"
Style="max-width: 500px" DataKeyNames="Id" EnableViewState="true" OnPageIndexChanging="GridView1_PageIndexChanging">
<Columns>
<asp:ButtonField CommandName="Edit" ButtonType="Image" ImageUrl="~/image/redit.png" />
<asp:BoundField DataField="ProductName" HeaderText="Product Name" />
<asp:BoundField DataField="ProductDescription" HeaderText="Description" />
<asp:TemplateField>
<ItemTemplate>
<img src='data:image/jpg;base64,<%# Eval("ProductImage") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("ProductImage")) : string.Empty %>' alt="image" height="80" width="80" />
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="Delete" ButtonType="Image" ImageUrl="~/image/rdelete.png" />
</Columns>
<PagerStyle HorizontalAlign = "Right" />
</asp:GridView>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-footable/0.1.0/css/footable.min.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-footable/0.1.0/js/footable.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=GridView1]').footable();
});
</script>
这是我的aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
LoadGrid();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = int.Parse(e.CommandArgument.ToString());
string val = (string)this.GridView1.DataKeys[rowIndex]["Id"];
if (e.CommandName == "Edit")
{
}
else if (e.CommandName == "Delete")
{
}
}
public void LoadGrid()
{
try
{
BusinessLogic.clsGeneral objGen = new BusinessLogic.clsGeneral();
string strquery = "select * from Products where status = 1";
DataTable dt = objGen.ExecuteQueryReturnDatatable(strquery);
GridView1.DataSource = dt;
GridView1.DataBind();
GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
catch (Exception)
{
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
答案 0 :(得分:1)
尝试这样:
您需要在PageIndexChanging
事件
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
LoadGrid();
}
答案 1 :(得分:0)
将数据源agin添加到您的分页中,
尝试从您的代码中替换以下代码段。
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BusinessLogic.clsGeneral objGen = new BusinessLogic.clsGeneral();
string strquery = "select * from Products where status = 1";
DataTable dt = objGen.ExecuteQueryReturnDatatable(strquery);
GridView1.DataSource = dt;
GridView1.DataBind();
}
这里仍有一些要点
避免inLine查询,这看起来不太好
尽管再次调用数据绑定,你也可以使用其他一些技巧。
在Sql中,永远不会返回*(全部),只返回你需要的列集,*不是很好的做法。 例如。从....选择姓名,地址,电话,而不是选择* ...
答案 2 :(得分:-1)
{{serviceData | async}}