Datalist里面嵌套Gridview,如何实现Gridview分页?
OKMZY 2012-03-27 05:00:04 我在DataList里面嵌套一个GridView,要实现GridView的分页功能,而GridView里面的数据是根据DataList里面绑定的一个主表id为条件查询出来的。在GridView分页事件protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e)里面,需要再重新绑定GridView,但是这个主表id怎么才能传过来到GridView分页事件里面呢?
总之,我要实现Gridview分页,不知道还有其他解决办法没?代码如下:
private void BindFatherData()//绑定外层控件
{
classNews ser=new classNews();
DataTable dt = ser.GetTableBySql("select A.title,A.type,A.CNTT_NO from NewsMsg");
if (dt != null && dt.Rows.Count > 0)
{
this.DataList.ObjectDataSource = dt.DefaultView;
this.DataList.DataBind();
}
}
protected void DataPager1_PageIndexChanged(object sender, CIT.App.Lib.WebControls.PageChangedEventArgs e)
{
this.DataPager1.ControlToPaginate = this.DataList1.UniqueID;
BindFatherData();
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemIndex > -1)
{
classNews ser=new classNews();
GridView GV1 = (GridView)e.Item.FindControl("GVProcessing");//找到内层GridView控件
DataRowView drv = (DataRowView)e.Item.DataItem;
DataTable dt = ser.GetTableBySql(""select * from News a where a.ID='" + drv["ID"].ToString() + "'");
if (dt != null && dt.Rows.Count > 0)
{
GV1.DataSource = dt.DefaultView;
GV1.DataBind();
}
}
}