一个动态生成表格的类

using System;
using System.Data;
using System.Configuration;
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;

/// <summary>
/// ActiveTable 动态生成表格
/// </summary>
public class ActiveTable
{
    /// <summary>
    /// 构造函数
    /// </summary>
    public ActiveTable()
    {
    }
    /// <summary>
    /// 申明私有字段
    /// </summary>
    public object[,] m_Info;//信息内容
    public object[] m_Title;//表格标题
    public int m_Rows;//行数
    public int m_Columns = 0;//列数
    public string m_tbWidth; //表格宽度
    public string m_border = "1";//表格边界
    public string m_cellpadding = "0";
    public string m_fontSize = "18px;";//字体大小
    public string m_cellspacing = "0";
    public string m_TitlebackgroundColor = "White";//标题背景色
    public string m_backgroundColor = "White";//行的颜色
    public string m_align = "left";
    public bool m_isNeedTitle = true;//是否需要表头
    public string m_strWidth = "";//列的宽度
    public string m_ColumnCss="BORDER-TOP-STYLE: none";
    //public bool m_IsHaveChoiceControl;//是否显示选择控件
    //public bool m_ShowHcbxOrShowHrdo;//显示复选控件还是单选控件
    //public bool m_IsSetShowDetialInfo;//是否设置详细信息连接
    //public bool m_IsHaveChoiceControl;//是否显示选择控件
    //public string m_OtherUrl;//其他连接URL
    //public string m_tbWidth; //表格宽度
    //public bool m_IsSetOtherHerf;//是否设置其他连接操作
    //public bool m_ShowHcbxOrShowHrdo;//显示复选控件还是单选控件
    //public bool m_IsSetShowDetialInfo;//是否设置详细信息连接
    //public string m_DetialInfoUrl;//详细信息连接的URL
    //public bool m_IsHaveChoiceControl;//是否显示选择控件
    //public string m_strLinkName;//其他连接的名称
    //public string m_strLinkNameTitle;//其他连接名称的表格标题

    /// <summary>
    /// 创建动态表格
    /// </summary>
    /// <returns></returns>
    public string CreateActiveTable()
    {

        string strTotal = "";
        strTotal = "<table width='" + m_tbWidth + "' border='" + m_border + "' cellspacing='" + m_cellspacing + "' cellpadding='" + m_cellpadding + "' style=/"text-align:center; font-size:" + m_fontSize + "/" >";
        if (m_isNeedTitle == true)
        {
            for (int i = 1; i <= m_Rows; i++)
            {
                strTotal += "<tr >";

                for (int iCloum = 0; iCloum < m_Columns; iCloum++)
                {
                    if (i == 1)
                    {
                        strTotal += "<td style='height:25px;background-color:" + m_TitlebackgroundColor + "' width='" + m_strWidth + "'>";
                        strTotal += m_Title[iCloum];
                        strTotal += "</td>";
                    }
                    else
                    {
                        if (i % 2 == 0)
                            strTotal += "<td style='background-color:" + m_backgroundColor + "'>";
                        else
                            strTotal += "<td>";
                        strTotal += m_Info[i - 2, iCloum];
                        strTotal += "</td>";
                    }
                }
                strTotal += "</tr>";
            }
        }
        else
        {
            for (int i = 1; i <= m_Rows - 1; i++)
            {  
                strTotal += "<tr>";
                for (int iCloum = 0; iCloum < m_Columns; iCloum++)
                {
                    if (i % 2 == 0)
                        strTotal += "<td style='"+m_ColumnCss+";background-color:" + m_backgroundColor + "'  width='" + m_strWidth + "'>";
                    else
                        strTotal += "<td style='"+m_ColumnCss+"' width='" + m_strWidth + "'>";
                    strTotal += m_Info[i - 1, iCloum];
                    strTotal += "</td>";
                }
                strTotal += "</tr>";
            }
        }
        strTotal = strTotal + "</table>";
        return (strTotal);
    }

}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值