当前位置:编程学习 > C#/ASP.NET >>

循环输出给控件

  if (!IsPostBack)
        {
            string sqls = "select title,newsid from news where typeid=7 order by newsid desc";
            RepeatMessagebind(sqls, F_M_story, Pagination1);
            for (int i = 2; i <= 20; i++)
            {
                int y = 8;
                int x = i + y;
                string sql = "select title,newsid from news where typeid=" + x + " order by newsid desc";
                string no = "Repeater" + Convert.ToString(i - 1);
                Repeater t = new Repeater();
                t.ID = no;
                string not = "Pagination" + Convert.ToString(i);
                Pagination namet = new Pagination();
                namet.ID = not;
                RepeatMessagebind(sql, t, namet);

            }

        }
帮忙看下哪里有错 --------------------编程问答-------------------- 你想干嘛,有错说错 --------------------编程问答-------------------- 没错 我想循环输出给页面的控件 
 string no = "Repeater" + Convert.ToString(i - 1);
  Repeater t = new Repeater();
  t.ID = no;
  string not = "Pagination" + Convert.ToString(i);
  Pagination namet = new Pagination();
  namet.ID = not;
  RepeatMessagebind(sql, t, namet);
这部分没报错 但没达到我的效果 我绑定了ID 名给 t 但好像不能给前台页面的 同一ID 的 控件赋值 --------------------编程问答-------------------- 其实就是多控件绑定的问题 没人知道么 --------------------编程问答-------------------- 参考:
public void ArtList(int sType,Repeater rpt)
   {
   SqlConnection myConn = DB.GetConnection();
   string strSql = "Select ID,oTitle,oNow From News Where 1 = 1";
   if (sType != null && sType != 0)
   {
   strSql += " And oBid = " + sType + " ";
   }
   strSql += " Order By Id Desc";
   SqlCommand oIsCmd = new SqlCommand(strSql, myConn);
   myConn.Open();
   rpt.DataSource = oIsCmd.ExecuteReader();
   rpt.DataBind();
   myConn.Close();
   }

调用:
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ArtList(1, this.RepeaterList);
            ArtList(2, this.Repeater1);
        }
    } --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 除
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,