后台代码如下:string sql_string = "select * from Notice where Id=" + Id.ToString ();
                string[] K_text ={ TB_Title.Text, TB_Author.Text, FCK_Content.Value, TB_Time.Text, TB_Class.Text, TB_IsPub.Text, TB_State.Text };
                datahelper datahelp = new datahelper();
                datahelp.getdata(sql_string, K_text);
                datahelp.getdata(sql_string ,K_text );
这是datahelper类中的方法:
  public void getdata(string sql_string,string []K_text)
    {
        sqlcon = new SqlConnection(strCon);          
        SqlDataAdapter myAdap = new SqlDataAdapter(sql_string, sqlcon);
        DataSet myds = new DataSet();
        myAdap.Fill(myds, "Notice");
        for (int i = 0; i < K_text.Length; i++)
        {
            K_text[i] = myds.Tables ["Notice"].Rows[0][i].ToString ();
        }
    }
结果只是把数据赋值到数组而已,控件上没有显示,请问如何在保留数组的情况下在控件上显示? 难道要一个一个的赋值?

解决方案 »

  1.   

    public sting []getdata(string sql_string)
      {
      sqlcon = new SqlConnection(strCon);   
      SqlDataAdapter myAdap = new SqlDataAdapter(sql_string, sqlcon);
      DataSet myds = new DataSet();
      myAdap.Fill(myds, "Notice");
      int count=0;
      count=myds.Tables["Notice"].Rows.count
      string []K_text=new string[count];
      for (int i = 0; i < count; i++)
      {
      K_text[i] = myds.Tables ["Notice"].Rows[0][i].ToString ();
      }
      return K_text;
      }
    后台:
    datahelper datahelp = new datahelper();
     string[] K_text =datahelp.getdata(sql_string, K_text);
    然后TB_Title.Text=K_text[0];如此如此
      

  2.   

    ref 传递数组
    ref string []K_text
      

  3.   

    如果不想用三楼的方法,你可以试一个用foreach遍历控件的方法
      

  4.   

    你可以用object数组把控件给传过去,然后再foreach 赋值人不能太懒
      

  5.   

    要是绑定到text或者label等的控件上,不循环不行吧。
    你可以用repeater或者datalist等绑定,在repeater或者datalist中加一个Text或者lable标签,
    然后前台绑定字符串,后台像绑定数据集一样绑定一下数组就可以了
      

  6.   

    建议你使用model 就是李天平的三层架构