private void drawtable()
    {
        SqlConnection myconn = new SqlConnection(conn);
        myconn.Open();
        SqlCommand cmd = new SqlCommand("select serverid,servername,servercontent from server where serverid%2=1", myconn);
        int count = (int)cmd.ExecuteScalar();
        SqlDataReader dataread = cmd.ExecuteReader();
        Response.Write(count);
        string output="<table width='300' border='0' cellspacing='0' cellpadding='0'>";
        while (dataread.Read())
        {
            output += "<tr><td background=images/zxfw_16_01.jpg width=139 height=26>" + dataread["servername"].ToString();
            output += "</td>";//服务名称
            output += "<td width=66 height=26 bgcolor=#C6E2F0>更多</td>";//该服务内容的详细问题列表
            output += "</tr>";
            output += "<tr><td colspan=2 background=Images/zxfw_24_02.jpg>" + dataread["servercontent"].ToString();
            output += "</td>";//该服务的简单介绍
            output += "</tr>";
            SqlConnection myconn1 = new SqlConnection(conn);
            myconn1.Open();
            SqlCommand cmd1 = new SqlCommand("select questionid,questiontitle from question where serverid='" + dataread["serverid"] + "'", myconn1);
            SqlDataReader datareadtitle = cmd1.ExecuteReader();
            while (datareadtitle.Read())
            {
                output += "<tr>";
                output += "<td colspan=2 background=Images/zxfw_24_02.jpg>" + datareadtitle["questiontitle"].ToString();
                output += "</td>";//该服务下的问题列表
                output += "</tr>";
            }
            output += "<tr>";
            output += "<td colspan=2><img src=Images/zxfw_26.jpg width=345 height=6></td>";
            output += "</tr>";
            output += "<tr>";
            output += "<td colspan=2 height=3><img src=images/zxfw_24_03.jpg width=345 height=3></td>";
            output += "</tr>";        }
        output += "</table>";
        Response.Write(output); 
    }问个问题啊,如何把这个在后台通过代码画的表格在页面的指定单元格里循环画表呢??

解决方案 »

  1.   

    <% drawtable() %>另外,建议方法加上参数,加上返回值,直接这样肯定是不能循环画表的
      

  2.   

    public string drawtable(int type)
        {
            SqlConnection myconn = new SqlConnection(conn);
            myconn.Open();
            SqlCommand cmd = new SqlCommand("select serverid,servername,servercontent from server where serverid%2=1", myconn);
            int count = (int)cmd.ExecuteScalar();
            SqlDataReader dataread = cmd.ExecuteReader();
            Response.Write(count);
            string output=" <table width='300' border='0' cellspacing='0' cellpadding='0'> ";
            while (dataread.Read())
            {
                output += " <tr> <td background=images/zxfw_16_01.jpg width=139 height=26> " + dataread["servername"].ToString();
                output += " </td> ";//服务名称
                output += " <td width=66 height=26 bgcolor=#C6E2F0> 更多 </td> ";//该服务内容的详细问题列表
                output += " </tr> ";
                output += " <tr> <td colspan=2 background=Images/zxfw_24_02.jpg> " + dataread["servercontent"].ToString();
                output += " </td> ";//该服务的简单介绍
                output += " </tr> ";
                SqlConnection myconn1 = new SqlConnection(conn);
                myconn1.Open();
                SqlCommand cmd1 = new SqlCommand("select questionid,questiontitle from question where serverid='" + dataread["serverid"] + "'", myconn1);
                SqlDataReader datareadtitle = cmd1.ExecuteReader();
                while (datareadtitle.Read())
                {
                    output += " <tr> ";
                    output += " <td colspan=2 background=Images/zxfw_24_02.jpg> " + datareadtitle["questiontitle"].ToString();
                    output += " </td> ";//该服务下的问题列表
                    output += " </tr> ";
                }
                output += " <tr> ";
                output += " <td colspan=2> <img src=Images/zxfw_26.jpg width=345 height=6> </td> ";
                output += " </tr> ";
                output += " <tr> ";
                output += " <td colspan=2 height=3> <img src=images/zxfw_24_03.jpg width=345 height=3> </td> ";
                output += " </tr> ";        }
            output += " </table> ";
            return output;
            //Response.Write(output); 
        } 类似这样,把这个方法放到你的循环里
      

  3.   


    string d = "<table border=1><tr><td>dddd</td></tr></table>";
            Label1.Text = d;
      

  4.   

    <% drawtable() %> 另外,建议方法加上参数,加上返回值,直接这样肯定是不能循环画表的public string drawtable(int type)
        {
            SqlConnection myconn = new SqlConnection(conn);
            myconn.Open();
            SqlCommand cmd = new SqlCommand("select serverid,servername,servercontent from server where serverid%2=1", myconn);
            int count = (int)cmd.ExecuteScalar();
            SqlDataReader dataread = cmd.ExecuteReader();
            Response.Write(count);
            string output=" <table width='300' border='0' cellspacing='0' cellpadding='0'> ";
            while (dataread.Read())
            {
                output += " <tr> <td background=images/zxfw_16_01.jpg width=139 height=26> " + dataread["servername"].ToString();
                output += " </td> ";//服务名称
                output += " <td width=66 height=26 bgcolor=#C6E2F0> 更多 </td> ";//该服务内容的详细问题列表
                output += " </tr> ";
                output += " <tr> <td colspan=2 background=Images/zxfw_24_02.jpg> " + dataread["servercontent"].ToString();
                output += " </td> ";//该服务的简单介绍
                output += " </tr> ";
                SqlConnection myconn1 = new SqlConnection(conn);
                myconn1.Open();
                SqlCommand cmd1 = new SqlCommand("select questionid,questiontitle from question where serverid='" + dataread["serverid"] + "'", myconn1);
                SqlDataReader datareadtitle = cmd1.ExecuteReader();
                while (datareadtitle.Read())
                {
                    output += " <tr> ";
                    output += " <td colspan=2 background=Images/zxfw_24_02.jpg> " + datareadtitle["questiontitle"].ToString();
                    output += " </td> ";//该服务下的问题列表
                    output += " </tr> ";
                }
                output += " <tr> ";
                output += " <td colspan=2> <img src=Images/zxfw_26.jpg width=345 height=6> </td> ";
                output += " </tr> ";
                output += " <tr> ";
                output += " <td colspan=2 height=3> <img src=images/zxfw_24_03.jpg width=345 height=3> </td> ";
                output += " </tr> ";        }
            output += " </table> ";
            return output;
            //Response.Write(output); 
        } 
    能给一个详尽的代码么??int type不知道作用,以及引用方法先谢谢啊