一个页面中有一个DataGrid和一个DataList,现在翻页功能有问题,求助
我最近要修改一个别人做的页面,此页面的功能是这样的:
页面左边是一个DataList,显示一个列表;点击列表中的某一条信息,会在页面的右面显示详细内容,右边也是一个DataList
用着用着出现了一个问题,页面左边的列表会很长很长,没分页功能。
为了增加分页功能,我就把左边的DataList改成了一个DataGrid,后台代码如下——
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindContent();
            DataListDataBind();
        }
    }
    //我新加的代码,左边的DataGrid
    protected void DataListDataBind()
    {
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["Conn"]);
        string sqlStr = "select Miscel_ID,Miscel_TitleCn from Miscel order by Miscel_ID desc";
        SqlDataAdapter ad = new SqlDataAdapter(sqlStr, conn);
        DataSet dst = new DataSet();
        ad.Fill(dst, "ZD_Miscel");
        conn.Open();
        this.DataGrid1.DataSource = dst.Tables["ZD_Miscel"];
        this.DataGrid1.DataBind();
        conn.Close();
    }
    //我新加的代码,左边的DataGrid分页
    protected void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
        DataGrid1.CurrentPageIndex = e.NewPageIndex;
        DataListDataBind();
        try
        {
            this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
        }
        catch
        {
            this.DataGrid1.CurrentPageIndex = 0;
        }
        this.DataListDataBind();
    }
//旧代码,人家写的,右边的DataList
private void BindContent()
    {
        int id = 0;
        string queryString = "";
        if (Request.QueryString["id"] != null)
        {
            id = Convert.ToInt32(Request.QueryString["id"]);
            queryString = "select * from Miscel where Miscel_ID = " + id;
        }
        else
        {
            queryString = "select top 1 * from Miscel order by Miscel_ID desc";
        }
        PublicSql pub = new PublicSql();
        pub.BindDataList(queryString, mContent);
    }
这样写好以后,翻页功能正常了
但是当翻到第二页的时候,点击DataGrid里面的列表后,右面的DataList显示内容的同时,DataGrid列表会自动跳回第一页
不知道该添加一个什么东西,求达人相助
------解决方案--------------------
public static class CP
   {
       public static int aaa;
   }
然后
CP.aaa = e.NewPageIndex;