我做个在线咨询和点评的界面。
布局是在线咨询和点评在同一个界面,一个咨询对应多个点评,咨询有上下页的按钮,
点评也有上下页的按钮,现在出现问题了,就是不好让它们对应的显示。
怎么个思路呀???实现的功能是:点击咨询的翻页,对应的点评更新,点击点评时,对应的咨询部翻页。可是我现在点击点评时,咨询也翻页!!!
我分别写了二个上下页  public partial class TestOK : System.Web.UI.Page
    {
        private SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString);
        Hashtable ht = new Hashtable();
        public int num = 1;
        public int PageNum = 0;
        public bool F = true;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string str = "";
                if (F)
                {
                    string strTxt = "select * from online order by id";
                    repText.DataSource = pdsTxt(strTxt);
                    repText.DataBind();
                }
                foreach (int Ok in ht.Keys)
                {
                    if (PageNum == Ok)
                    {
                        str = "select * from dp where dp.id= " + ht[Ok] + "";
                    }
                }
                repans.DataSource = pds(str);
                repans.DataBind();
            }        }        public PagedDataSource pdsTxt(string strTxt)
        {
            SqlCommand com = new SqlCommand(strTxt, conn);
            SqlDataAdapter adapter = new SqlDataAdapter(com);
            DataSet ds = new DataSet();
            conn.Open();
            adapter.Fill(ds);
            PagedDataSource pds = new PagedDataSource();
            com.Dispose();
            conn.Close();
            pds.DataSource = ds.Tables[0].DefaultView;
            pds.AllowPaging = true;
            pds.PageSize = 1;
            int Pageindex;
            if (Request.QueryString["page"] != null)
            {
                Pageindex = Convert.ToInt32(Request.QueryString["page"]);
            }
            else
            {
                Pageindex = 1;
            }
            //设置当前页
            if (Pageindex < 1)
            {
                Pageindex = 1;
            }
            pds.CurrentPageIndex = Pageindex - 1;
            repText.DataSource = pds;
            repText.DataBind();
            //显示上下翻页
            lbn_Prev.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (Pageindex - 1);
            lbn_Next.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (Pageindex + 1);
            //确定链接的显示方式
            if (Pageindex <= 1 && pds.PageCount <= 1)
            {
                lbn_Prev.NavigateUrl = "";
                lbn_Next.NavigateUrl = "";
            }
            if (Pageindex <= 1 && pds.PageCount > 1)
            {
                lbn_Prev.NavigateUrl = "";
            }
            if (Pageindex >= pds.PageCount)
            {
                lbn_Next.NavigateUrl = "";
            }
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                ht.Add(num++, row["ID"]);
            }
            PageNum = Pageindex;
            return pds;
        }        public PagedDataSource pds(string str)
        {
            SqlCommand com = new SqlCommand(str, conn);
            SqlDataAdapter adapter = new SqlDataAdapter(com);
            DataSet ds = new DataSet();
            conn.Open();
            adapter.Fill(ds);
            PagedDataSource pds = new PagedDataSource();
            com.Dispose();
            conn.Close();
            //设置数据源(DataTable类型)
            pds.DataSource = ds.Tables[0].DefaultView;
            //允许分页
            pds.AllowPaging = true;
            //每页显示的行数
            pds.PageSize = 1;
            repans.DataSource = pds;
            repans.DataBind();
            int Pageindex;
            //当前页面从Page查询参数获取
            if (Request.QueryString["page"] != null)
            {
                Pageindex = Convert.ToInt32(Request.QueryString["pageT"]);
            }
            else
            {
                Pageindex = 1;
            }
            //设置当前页
            if (Pageindex < 1)
            {
                Pageindex = 1;
            }
            pds.CurrentPageIndex = Pageindex - 1;
            //显示上下翻页
            lbn_APre.NavigateUrl = Request.CurrentExecutionFilePath + "?pageT=" + (Pageindex - 1);
            lbn_ANext.NavigateUrl = Request.CurrentExecutionFilePath + "??pageT=" + (Pageindex + 1);
            //确定链接的显示方式
            if (Pageindex <= 1 && pds.PageCount <= 1)
            {
                lbn_APre.NavigateUrl = "";
                lbn_ANext.NavigateUrl = "";
            }
            if (Pageindex <= 1 && pds.PageCount > 1)
            {
                lbn_APre.NavigateUrl = "";
            }
            if (Pageindex >= pds.PageCount)
            {
                lbn_ANext.NavigateUrl = "";
            }
            return pds;
        }        protected void ImgbtnOK_Click(object sender, ImageClickEventArgs e)
        {
            //pdsSql(Convert.ToInt32(txtbox1.Text.Trim()), strSql);
        }
    }

解决方案 »

  1.   

      Hashtable ht = new Hashtable(); 
      public int PageNum = 0; 
    这是想保存咨询的ID,以便点评对应显示
      

  2.   

    你说的有点不理解,咨询和点评,应该是一对多的关系,可你又说点击点评咨询也翻页,难道一条点评对应几条咨询吗?不对吧!我的思路是这样,点击咨询的下一些,获取下一个咨询的ID,然后根据该ID获取和该ID对应的所有点评就行了 啊!应该不难实现,只是我手上现在没有现成的例子!
      

  3.   

    主要是怎么能获得资讯的ID
    我咨询的ID是点评的外键,
    现在的问题是不好获取当前页的咨询ID,
      

  4.   

    gridview或reapter嵌套,第一层显示咨询
    protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e) 
            { 
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
                { 
                  Repeater rep = e.Item.FindControl("Repeater2") as Repeater; 
                  DataRowView rowv = (DataRowView)e.Item.DataItem; 
                            
                } 
            } http://topic.csdn.net/u/20090911/14/5267b5fc-0ac7-43e0-840a-639b38610479.html
      

  5.   

    现在的代码更新了:
     private SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString);
            protected void Page_Load(object sender, EventArgs e)
            {
                ParentRepeater.ItemDataBound += new RepeaterItemEventHandler(ParentRepeater_ItemDataBound);
                if (!IsPostBack)
                {
                    string strTxt = "select * from online order by id";
                    SqlCommand com = new SqlCommand(strTxt, conn);
                    SqlDataAdapter adapter = new SqlDataAdapter(com);
                    DataSet ds = new DataSet();
                    conn.Open();
                    adapter.Fill(ds);
                    PagedDataSource pds = new PagedDataSource();
                    conn.Close();
                    pds.DataSource = ds.Tables[0].DefaultView;
                    pds.AllowPaging = true;
                    pds.PageSize = 1;
                    int Pageindex;
                    if (Request.QueryString["page"] != null)
                    {
                        Pageindex = Convert.ToInt32(Request.QueryString["page"]);
                    }
                    else
                    {
                        Pageindex = 1;
                    }
                    //设置当前页
                    if (Pageindex < 1)
                    {
                        Pageindex = 1;
                    }
                    pds.CurrentPageIndex = Pageindex - 1;
                    ParentRepeater.DataSource = pds;
                    ParentRepeater.DataBind();
                    //显示上下翻页
                    lbn_Prev.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (Pageindex - 1);
                    lbn_Next.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (Pageindex + 1);
                    //确定链接的显示方式
                    if (Pageindex <= 1 && pds.PageCount <= 1)
                    {
                        lbn_Prev.NavigateUrl = "";
                        lbn_Next.NavigateUrl = "";
                    }
                    if (Pageindex <= 1 && pds.PageCount > 1)
                    {
                        lbn_Prev.NavigateUrl = "";
                    }
                    if (Pageindex >= pds.PageCount)
                    {
                        lbn_Next.NavigateUrl = "";
                    }
                }
            }        void ParentRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    DataRowView row = (DataRowView)e.Item.DataItem;
                    string parentID = row["ID"].ToString();
                    string strSql = "select * from dp where id=" + parentID + " order by C_ID";
                    SqlCommand com = new SqlCommand(strSql, conn);
                    SqlDataAdapter adapter = new SqlDataAdapter(com);
                    DataSet ds = new DataSet();
                    adapter.Fill(ds);
                    ChildRepeater.DataSource = ds.Tables[0].DefaultView;
                    ChildRepeater.DataBind(); 
                }
            }
    现在能实现的只是:点击咨询上下页,下面的点评能对应都显示出来,可是我想把点评也分页显示出来,也有使用上下页的功能,可是当我加进去时,就出问题了就是使用点评上下页功能时,咨询就跳到第一页显示,我想实现点击点评上下页时,咨询不变化
      

  6.   

    原来的可以传两个参数
    Page=XXX&PageT=XXX
      

  7.   

    //显示上下翻页 
    lbn_Prev.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (Pageindex - 1); 
    lbn_Next.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (Pageindex + 1); 
    你用链接来实现翻页相当于跳转到新页面,不在原来页面上了,一定会重新载入咨询部分的啊,像这样就要像16喽说的传两个参数,一个是咨询的当前页,一个是评价的当前页。
      

  8.   

    可能是这两句,我看错了//显示上下翻页 
    lbn_APre.NavigateUrl = Request.CurrentExecutionFilePath + "?pageT=" + (Pageindex - 1); 
    lbn_ANext.NavigateUrl = Request.CurrentExecutionFilePath + "??pageT=" + (Pageindex + 1);咨询部分的翻页可以只传一个参数,评价部分的翻页就要同时传两个参数。
      

  9.   

    看你的代码好像不是像你说的那样是两个部分的关系,而是一个主从表的关系,咨询是主表,评价是从表,是这样吗?因为如果不是这样的话,你把评价的数据绑定写在ItemDataBound事件中就没有道理了。如果是像你描述的一样是两个部分的关系,那么两个部分分开写就不会有你说的问题了。楼主最好把整个情况描述地更清楚一点。
      

  10.   

    觉得显示不好控制啊
    咨询列



    点评列



    楼主最好是
    选择一条咨询列或点评列,查询一次相关的记录绑定repeater
    然后主要的还是用户可以点击一个"全部的点评" link进行恢复加载全部数据。