自己想了个方法,请高手指点下: int nRow = ds.Tables[0].Rows.Count; if (nRow > 0) { for (int i = 0; i < nRow; i = i + 10) { for (int j = i; j < i + 10; j++) { .... } } }
DataSet ds = new DataSet(); DataTable dt = DataSet.Tables[0]; int rows = dt.Rows.Count; for(int i = 0;i<rows;i++) { DataTable clone = dt.Clone(); clone.Rows.Add(dt.Rows[i]) if(i%10==0 || i==rows) {ds.Tables.Add(clone);continue;} }
DataSet Ds = new DataSet(); DataSet[] arrDs = new DataSet[Ds.Tables[0].Rows.Count % 10]; for (int i = 0; i < Ds.Tables[0].Rows.Count; i++) { arrDs[(int)(i / 10)].Tables[0].Rows[i][0] = Ds.Tables[0].Rows[i][0].ToString(); } 这样试试,我没测试
if(Session["product"]!=null)
{
if(IsPostBack)
{
dt=(DataTable)Session["product"];
for(int i=0;i<dt.Rows.Count;i++)
{
dt.Rows[i]["quantity"]=Convert.ToInt32(((TextBox)dg.Items[i].FindControl("tb")).Text);
dt.Rows[i]["sum"]=(int)dt.Rows[i]["quantity"] * Convert.ToInt32(dt.Rows[i]["price"]); if((int)dt.Rows[i]["quantity"]==0)
{
dt.Rows[i].Delete();
}
}
Session["product"]=dt;
}
dt=(DataTable)Session["product"];
dg.DataSource=dt;
dg.DataBind();
-------------------------
偶新手,麻烦给我个适合我问题的解决方案呀,大侠~include_me(丁一)
-------------------------
老兄,给个思路哈。。
int nRow = ds.Tables[0].Rows.Count;
if (nRow > 0)
{
for (int i = 0; i < nRow; i = i + 10)
{
for (int j = i; j < i + 10; j++)
{
....
}
}
}
DataTable dt = DataSet.Tables[0];
int rows = dt.Rows.Count;
for(int i = 0;i<rows;i++)
{
DataTable clone = dt.Clone();
clone.Rows.Add(dt.Rows[i])
if(i%10==0 || i==rows)
{ds.Tables.Add(clone);continue;}
}
DataSet[] arrDs = new DataSet[Ds.Tables[0].Rows.Count % 10]; for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
{
arrDs[(int)(i / 10)].Tables[0].Rows[i][0] = Ds.Tables[0].Rows[i][0].ToString();
}
这样试试,我没测试
DataTable DT=ds.Table[0];
DataSet dsnew=New DataSet();
int j=1;//代表页数
for(int i=0;i<DT.Rows.Count;i++)
{
if(i<j*10&&j>(j-1)*10)
{ }
}
并绑定到GridView上,
GridView启用分页功能.
处理 PageIndexChanging 事件
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
this.GridView1.DataSource = ViewState["data"] as System.Data.DataTable;
this.GridView1.DataBind();
}
{
DataTable dt;
DataSet ds = new DataSet();
int i=0;
while(i<dataSet.Tables["tableName"].Rows.Count)
{
int j=0;
dt= = new DataTable();
while(j<dataSet.Tables["tableName"].Rows.Count&&j<10)
{
DataRow dr = dataSet.Tables["tableName"].Rows[j];
dt.ImportRow(dr);
}
i = j;
ds.Tables.Add(dt);
}
}
或者用数据库当中的游标,DataTable多慢啊?