動態生成表格,金額轉換,datatable

 

創建動態表格:

HtmlTable table = new HtmlTable();  //表格創建完成

        for (int i = 0; i < 5; i++)  //控制行

        {

            HtmlTableRow row = new HtmlTableRow();

            for (int j = 0; j < 5; j++)  //控制單元格

            {

                HtmlTableCell cell= new HtmlTableCell();

                //cell.InnerHtml = string.Format("i:{0};j:{1}", i, j);

                row.Cells.Add(cell);

            }

生成的htmltable

 

Table t = new Table();

        for (int i = 0; i < 3; i++)

        {

            TableRow row = new TableRow();

            for (int j = 0; j < 2; j++)

            {

                TableCell cell = new TableCell();

                Button btn = new Button();

                btn.Text = i.ToString() + j.ToString();

                cell.Controls.Add(btn);

                row.Cells.Add(cell);

            }

            t.Rows.Add(row);

        }

        this.Panel1.Controls.Add(t);

生成web服務器控件table

 

人民幣轉換:

public static string ToChineseNumber<T>(T num)

使用泛型

string[] chinesePos = new string[] { "圓", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億" };

string[] chinese = new string[]{"零","壹","貳","叄","肆","伍","陸","柒","捌","玖"};

定義兩個數組分別用來取位和轉換成大寫

string strNum = num.ToString();   //要轉換數字的字符串形式        

string oneNum = "";   //用來存儲一個數字

StringBuilder sb = new StringBuilder();  //用來存儲轉換之後的結果     

            int dotPos = strNum.IndexOf(".");

            string integer = "";  //整數部分

            if (dotPos != -1)

                integer = strNum.Substring(0, dotPos);

            else

                integer = strNum;

 

使用interger保存整數部分

while (integer.Length > 0)

{  //轉換整數部分

     int len = integer.Length;  //數字長度

     oneNum = integer.Substring(0, 1); //取高位數字

     integer = integer.Substring(1);   //取出剩餘數字,刪掉高位數字

      sb.Append(chinese[int.Parse(oneNum)]);//添加高位數字對應的大寫

      sb.Append(chinesePos[len - 1]);  //添加數字對應的位權

  }

整數部分轉換完成,轉換小數

if (dotPos != -1)

    {  //轉換小數部分

        string little = strNum.Substring(dotPos + 1);

        if (little.Length > 1)

{

           sb.Append(chinese[int.Parse(little.Substring(0, 1))]).Append("角");  //數字

            sb.Append(chinese[int.Parse(little.Substring(1, 1))]).Append("分");  //數字

                }

            }

            return sb.ToString();

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章