GridView绑定的不同的数据源的分页问题

2024-11-28 10:05:45
推荐回答(2个)
回答1:

给你个思路 做个统一的defaultview

我不是你是datatable ds 还是先调用的sql数据源!

回答2:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Model;
using BLL;

public partial class Admin_LookGoods : System.Web.UI.Page
{

bool isone = false;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["AdminName"] == null)
{
Response.Redirect("AdminLogin.aspx");
}
if (!Page.IsPostBack)
{
ViewState["id"] = Request.QueryString["id"];
ViewState["page"] = 0;
try
{
DBini();
}
catch
{
Response.Redirect("Order.aspx");
}
}
}

public void DBini()
{
DataTable dt;
if (isone == false)
{
dt = OrderGoodsBLL.GetAll(Convert.ToInt32(ViewState["id"].ToString()));
}
else
{
dt = OrderGoodsBLL.GetAllByTwo(Convert.ToInt32(ViewState["id"].ToString()), ViewState["name"].ToString());
}

GridView1.AllowPaging = true;
GridView1.PageSize = 9;
GridView1.PageIndex = Convert.ToInt32(ViewState["page"]);

GridView1.DataSource = dt;
GridView1.DataBind();

}
protected void Button1_Click(object sender, EventArgs e)
{
ViewState["name"] = TextBox1.Text;
isone = true;
DBini();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((LinkButton)(e.Row.Cells[4].Controls[0])).Attributes.Add("onclick", "return confirm('确认要删除吗?')");
}

}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
OrderGoodsBLL.Delete(id);
DBini();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
ViewState["page"] = e.NewPageIndex;
DBini();
}
}

------------------------------------------------------

上面代码帮不了你的话,
想要更灵活的查询并显示数据,请使用repeater加上aspnetpager