分数都用光了。。但希望各位多帮帮忙。。非常感谢
网页里创建了
<asp:Table ID="usertable" runat="server" Width="30px">
</asp:Table>

相应的cs为:

protected void Button4_Click(object sender, EventArgs e)
        {
            String sql = "select * from user_info";
            string[] th = { "id", "用户名", "密码" };
            string[] getname = { "id", "username", "password" };
            this.usertable =  CreatTable.cTable(sql, th, getname);
           
        }

调用的CreatTable类为:
 public static  Table cTable(string sql, string[] thname,string[] getname)
        {            int col = thname.Length;
            Table ct = new Table();
            ct.BorderWidth = 2;
            TableRow th = new TableRow();
            for (int i = 0; i < col; i++)
            {
                TableCell thc = new TableCell();
                thc.Width = 100;
                thc.Text = thname[i];
                th.Cells.Add(thc);
            }
            //取出查询的结果
            DataSet ds = DB.dbSearch(sql);
            if (ds.Tables[0].Rows.Count == 0)
            {            }
            else
            {
                for(int j=0;j<ds.Tables[0].Rows.Count;j++)
                {
                    TableRow tr = new TableRow();
                    for (int i = 0; i < col; i++)
                    {
                        TableCell tc = new TableCell();
                        tc.Text = ds.Tables[0].Rows[j][getname[i]].ToString();
                        tc.Width = 100;
                        tr.Cells.Add(tc);
                    }                    ct.Rows.Add(tr);                }
            }
            return ct;        }

解决方案 »

  1.   

    没用过这样的方式,TABLE类型是不是对应??
      

  2.   

    使用JS吧。
    var tb =document.getElementById('TableID')
    for ( var i = 0 ; i < tb.rows.length; i++)
    {}
      

  3.   

    谢谢啊!我也不太清楚,昨天才从jsp学习asp.net的。
    但是如果不调用类里面的方法,直接把它放在按钮事件中,用<asp:table>直接添加行是可以实现的。
      

  4.   


    ct.Rows.Add(tr); 应该放到for循环中。
      

  5.   

    上面的问题主要是这里:
    this.usertable =  CreatTable.cTable(sql, th, getname); 
      

  6.   

    在cTable方法中不要再创建Table了,直接用你页面上的usertable给它添加row就行了
      

  7.   

    <C# code>
    </code>