protected void getListTop(int classID) {
            DataTable dt=listTop.getListTop(classID);
            dt.Columns.Add("Ntitle");//增加一列Ntitle            string sql = "select * from NewsNotes where NewsclassID =" + classID.ToString();
            DataTable dtxxx = new DataTable();
            OleDbConnection con = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["connectionstring"].ToString());
            OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
            da.Fill(dtxxx);
            
            if (dt.Rows.Count > 0)
            {   
                DataRow dr = dt.Rows[0];                dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来!
                                
                this.RepeartListTop.DataSource = dt;
                this.RepeartListTop.DataBind();
}
}
请问下我把这个梆定在REpear里可以把dt里面的内容全循环出来了.
为什么Ntitle的内容只能显示第一条呢?

解决方案 »

  1.   

    DataRow dr = dt.Rows[0]; 
    ["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来! 
     你只给第一行的Ntitle 列赋值了,其他都没赋值
      

  2.   

    if (dt.Rows.Count > 0) 
                {  
                    DataRow dr = dt.Rows[0];                 dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来! 
                                    
                    this.RepeartListTop.DataSource = dt; 
                    this.RepeartListTop.DataBind(); 

    这段有问题,应该在 dt中做循环啊。 
    foreach (DataRow drData in dt.Rows)

        dr["Ntitle"] = drData[2].ToString();//把Ntitle 从数据取出来! 
                                    
                   }
     this.RepeartListTop.DataSource = dt; 
                    this.RepeartListTop.DataBind(); 
      

  3.   

    有2个问题 DataTable dt=listTop.getListTop(classID); 
                dt.Columns.Add("Ntitle");//增加一列Ntitle 
    这个地方不能这样做
     (1) 首先该列没有字段类型(int,string...)
    建议你改成动态创建Datatable(2)你下面的只去第一行 dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来!的title 
      

  4.   

    我就是想不通怎样才能把Ntitle 不固定死值,,让从数据库里取出一行值的时候就加上另外一个表里的Ntitle的值..我也知道我取出来的是另外一个表的第一行第3列的值.
      

  5.   


    你这方法我试了下..不行啊..我是想从数据库里取出一行值的时候就加上另外一个表里的Ntitle的值..我也知道我取出来的是另外一个表的第一行第3列的值.
      

  6.   

    你的值没问题,但你并没有把你新增的dr 加到你的dt中。所以出现了问题。foreach (DataRow drData in dt.Rows)

        dr["Ntitle"] = drData[2].ToString();//把Ntitle 从数据取出来!
        dt.add(dr);//类似的意思,你改一下正确语句。                       
                  }
    this.RepeartListTop.DataSource = dt;
                    this.RepeartListTop.DataBind(); 
      

  7.   

    foreach (DataRow drData in dt.Rows)

        dr["Ntitle"] = drData[2].ToString();//把Ntitle 从数据取出来!
        dt.Rows.Add(dr);//类似的意思,你改一下正确语句。                       
                  }
    this.RepeartListTop.DataSource = dt;
                    this.RepeartListTop.DataBind(); 
      

  8.   

    for(int i=0;i<dt.Rows;i++){
    DataRow dr = dt.Rows[i]; 
    dr["Ntitle"] = dtxxx.Rows[i][2].ToString(); 
    }
                                    
      

  9.   

     if (dt.Rows.Count > 0) 
                {  
                    DataRow dr = dt.Rows[0];                 dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来! 
                                    
                    this.RepeartListTop.DataSource = dt; 
                    this.RepeartListTop.DataBind(); 
    } 你的这个if只对第一行进行了操作,其他行步没操作
      

  10.   

    for(int i=0;i <dt.Rows;i++){ 
    这样
      

  11.   


    if (dt.Rows.Count > 0) 
                {  
                    DataRow dr = dt.Rows[0];                 dr["Ntitle"] = dtxxx.Rows[0][2].ToString();//把Ntitle 从数据取出来! 
                                    
                    this.RepeartListTop.DataSource = dt; 
                    this.RepeartListTop.DataBind(); 

    这段有问题,应该在 dt中做循环啊。 
    foreach (DataRow drData in dt.Rows) 
    { 
        dr["Ntitle"] = drData[2].ToString();//把Ntitle 从数据取出来! 
                                    
                  } 
    this.RepeartListTop.DataSource = dt; 
                    this.RepeartListTop.DataBind(); 
      

  12.   

    这个。就不用高手了吧~不说有没有用for,你一个dtxxx.Rows[0][2].就是定了只有第0行了