创建表格的方法

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class ProvideMan_ProvideMan : System.Web.UI.Page
{
    DataAccess da = new DataAccess();

    protected void Page_Load(object sender, EventArgs e)
    {
        SqlParameter[] parm = new SqlParameter[1];
        parm[0] = new SqlParameter();
        parm[0].ParameterName = "@shortened";
        parm[0].SqlValue = txb_ProvideManShortened.Text;

        DataSet ds = da.RunProcedureToDs("supplier_id_shortened_s", parm);
        //provideManTable为div的id
        provideManTable.InnerHtml = CreateTable(ds.Tables[0]);
     }

public string CreateTable(DataTable dt)
    {
        string temp = "";
        temp += "<table style=/"border-right: #030303 1px solid; border-top: #030303 1px solid; border-left: #030303 1px solid;/" cellspacing=/"0/" cellpadding=/"0/" border=/"1/">";
        temp += "<tr style=/"background: #ccd3c9;/">";
        //第0列 代号
        temp += "<td style=/"width:130px; height: 22px; background-color: #dfd8c6; border-right: #6f6f6f 2px groove;border-bottom-style: none;/">货号</td>";
        //第1列 名称
        temp += "<td style=/"width:204px; height: 22px; background-color: #dfd8c6; border-right: #6f6f6f 2px groove; border-bottom-style: none;/">名称</td>";
        //第2列 地址
        temp += "<td style=/"width:80px; height: 22px; background-color: #dfd8c6; border-right: #6f6f6f 2px groove; border-bottom-style: none;/">颜色</td>";
        //第3列 联系人
        temp += "<td style=/"width:80px; height: 22px; background-color: #dfd8c6; border-right: #6f6f6f 2px groove; border-bottom-style: none;/">单位</td>";
        //第4列 电话
        temp += "<td style=/"width:80px; height: 22px; background-color: #dfd8c6; border-right: #6f6f6f 2px groove; border-bottom-style: none;/">数量</td>";
        temp += "</tr>";

        if (dt != null && dt.Rows.Count >= 1 || dt.Rows.Count < 1)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                temp += "<tr style=/"height:24px;/">";
                //第0列 代号
                temp += "<td style=/"width: 130px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += dt.Rows[i]["id"].ToString();
                temp += "</td>";
                //第1列 名称
                temp += "<td style=/"width: 204px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += dt.Rows[i]["supplier_name"].ToString();
                temp += "</td>";
                //第2列 地址
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                //temp += dt.Rows[i]["地址"].ToString();
                temp += "</td>";
                //第3列 联系人
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                //temp += dt.Rows[i]["联系人"].ToString();
                temp += "</td>";
                //第4列 电话
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                //temp += dt.Rows[i]["电话"].ToString();
                temp += "</td>";
                temp += "</tr>";
            }
            for (int k = 0; k < 6 - dt.Rows.Count; k++)
            {
                temp += "<tr>";
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                temp += "</td>";
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                temp += "</td>";
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                temp += "</td>";
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                temp += "</td>";
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                temp += "</td>";
                temp += "</tr>";
            }
        }
        else if (dt != null && dt.Rows.Count > 6)
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                temp += "<tr style=/"height:24px;/">";
                //第0列 代号
                temp += "<td style=/"width: 130px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += dt.Rows[i]["id"].ToString();
                temp += "</td>";
                //第1列 名称
                temp += "<td style=/"width: 204px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += dt.Rows[i]["supplier_name"].ToString();
                temp += "</td>";
                //第2列 地址
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                //temp += dt.Rows[i]["地址"].ToString();
                temp += "</td>";
                //第3列 联系人
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                //temp += dt.Rows[i]["联系人"].ToString();
                temp += "</td>";
                //第4列 电话
                temp += "<td style=/"width: 80px; border-left-style: none; border-right: #c0c0c0 1px solid;/">";
                temp += "&nbsp;";
                //temp += dt.Rows[i]["电话"].ToString();
                temp += "</td>";
                temp += "</tr>";
            }

        temp += "</table>";
        return temp;
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值