<asp:Table>的一些应用

 <asp:Table>在>.NET中是非常强大的,这个控件可以填充很多其它控件,下面我来举一些例子。

<xx.aspx>前台页面

<asp:Table ID="Table4" runat="server" CssClass="table_border" >                      
                    <asp:TableRow>
                        <asp:TableCell>Item</asp:TableCell>                       
                        <asp:TableCell>Part Name</asp:TableCell>
                        <asp:TableCell>Snap Shot</asp:TableCell>
                        <asp:TableCell>Project Status</asp:TableCell>
                        <asp:TableCell>Note</asp:TableCell>
                        <asp:TableCell>Part Order Quantity</asp:TableCell>
                        <asp:TableCell>Project Part Order Shipping Date after Sample Approval</asp:TableCell>
                        <asp:TableCell>Material for Samples</asp:TableCell>
                        <asp:TableCell>Materail for Production</asp:TableCell>                                   
                        <asp:TableCell>Shipping Notice</asp:TableCell>              
                                
                    </asp:TableRow>         
   </asp:Table>

 

<xx.aspx.cs>后台页面

  //显示Project Status & Shipping Notice
    protected void Show_StatusNotice(string projectnum)
    {
        TableRow row;
        TableCell cell;
        Image img;

        string strSql = "select * from status_notice ";
        strSql += " where projectnum='" + projectnum + "'";

        DataTable dt = CommonMySql.MySql_Select(strSql);
       
        int count = dt.Rows.Count;
        int k = 0;
        for (int i = 0; i < count; i++) //控制行数
        {
            k = i + 1;
            //新的一行
            row = new TableRow();           

            //添加第0列 item
            cell = new TableCell();
            Label lbl_item = new Label();
            lbl_item.ID = string.Concat("item_", k);
            lbl_item.Text = k.ToString();
            cell.Controls.Add(lbl_item);
            row.Cells.Add(cell);          

            //添加第1列 part number/name
            cell = new TableCell();
            cell.Style.Add("word-wrap", "break-word");//控制table换行
            cell.Width = 50;
            Label lbl_partname = new Label();
            lbl_partname.Width = 50;
            lbl_partname.ID = string.Concat("partname_", k);
            lbl_partname.Text = dt.Rows[i]["partname"].ToString();
            cell.Controls.Add(lbl_partname);
            row.Cells.Add(cell);

            //添加第2列 snap shot
            cell = new TableCell();
            img = new Image();
            img.Width = 50;
            img.Height = 40;
            img.ID = string.Concat("img_", k);
            img.ImageUrl = dt.Rows[i]["snapshot"].ToString();
            cell.Controls.Add(img);
            row.Cells.Add(cell);

            //添加第3列 Status
            cell = new TableCell();
            cell.Width = 320;
            Label lbl_ppt = new Label();
            lbl_ppt.ID = string.Concat("ppt_", k);
            lbl_ppt.Text = "● " + "Tooling Plan PPT ";
            cell.Controls.Add(lbl_ppt);          
            TextBox tb_ppt = new TextBox();
            tb_ppt.Width = 100;
            tb_ppt.ID = string.Concat("tbppt_",k);
            tb_ppt.Text = dt.Rows[i]["ppt"].ToString();
            cell.Controls.Add(tb_ppt);
            CheckBox chk_ppt = new CheckBox();
            chk_ppt.ID = string.Concat("chk_ppt", k);
            chk_ppt.Checked = Convert.ToBoolean(int.Parse(dt.Rows[i]["ppt_finish"].ToString()));
            cell.Controls.Add(chk_ppt);
            Label lbl_pptbr = new Label();
            //lbl_br.ID = string.Concat("br_", k);
            lbl_pptbr.Text = "<br/>";
            cell.Controls.Add(lbl_pptbr);

            Label lbl_design = new Label();
            lbl_design.ID = string.Concat("design_", k);
            lbl_design.Text = "● " + "Tooling Design Completed ";
            cell.Controls.Add(lbl_design);
            TextBox tb_design = new TextBox();
            tb_design.Width = 100;
            tb_design.ID = string.Concat("tbdesign_", k);
            tb_design.Text = dt.Rows[i]["design"].ToString();
            cell.Controls.Add(tb_design);
            CheckBox chk_design = new CheckBox();
            chk_design.ID = string.Concat("chk_design", k);
            chk_design.Checked = Convert.ToBoolean(int.Parse(dt.Rows[i]["design_finish"].ToString()));
            cell.Controls.Add(chk_design);
            Label lbl_designbr = new Label();
            lbl_designbr.Text = "<br/>";
            cell.Controls.Add(lbl_designbr);

            Label lbl_machining = new Label();
            lbl_machining.ID = string.Concat("machining_", k);
            lbl_machining.Text = "● " + "Tooling Machining ";
            cell.Controls.Add(lbl_machining);
            TextBox tb_machining = new TextBox();
            tb_machining.Width = 100;
            tb_machining.ID = string.Concat("tbmachining_", k);
            tb_machining.Text = dt.Rows[i]["machining"].ToString();
            cell.Controls.Add(tb_machining);
            CheckBox chk_machining = new CheckBox();
            chk_machining.ID = string.Concat("chk_machining", k);
            chk_machining.Checked = Convert.ToBoolean(int.Parse(dt.Rows[i]["machining_finish"].ToString()));
            cell.Controls.Add(chk_machining);
            Label lbl_machiningbr = new Label();
            lbl_machiningbr.Text = "<br/>";
            cell.Controls.Add(lbl_machiningbr);

            Label lbl_trail = new Label();
            lbl_trail.ID = string.Concat("trail_", k);
            lbl_trail.Text = "● " + "First Trail ";
            cell.Controls.Add(lbl_trail);
            TextBox tb_trail = new TextBox();
            tb_trail.Width = 100;
            tb_trail.ID = string.Concat("tbtrail_", k);
            tb_trail.Text = dt.Rows[i]["trail"].ToString();
            cell.Controls.Add(tb_trail);
            CheckBox chk_trail = new CheckBox();
            chk_trail.ID = string.Concat("chk_trail", k);
            chk_trail.Checked = Convert.ToBoolean(int.Parse(dt.Rows[i]["trail_finish"].ToString()));
            cell.Controls.Add(chk_trail);
            Label lbl_trailbr = new Label();
            lbl_trailbr.Text = "<br/>";
            cell.Controls.Add(lbl_trailbr);

            Label lbl_send = new Label();
            lbl_send.ID = string.Concat("send_", k);
            lbl_send.Text = "● " + "Send Samples for Approval ";
            cell.Controls.Add(lbl_send);
            TextBox tb_send = new TextBox();
            tb_send.Width = 100;
            tb_send.ID = string.Concat("tbsend_", k);
            tb_send.Text = dt.Rows[i]["send"].ToString();
            cell.Controls.Add(tb_send);
            CheckBox chk_send = new CheckBox();
            chk_send.ID = string.Concat("chk_send", k);
            chk_send.Checked = Convert.ToBoolean(int.Parse(dt.Rows[i]["send_finish"].ToString()));
            cell.Controls.Add(chk_send);
            Label lbl_sendbr = new Label();
            lbl_sendbr.Text = "<br/>";
            cell.Controls.Add(lbl_sendbr);

            row.Cells.Add(cell);

            //添加第4列 Note
            cell = new TableCell();
            cell.Style.Add("word-wrap", "break-word");//控制table换行
            cell.Width = 150;
            Label lbl_note = new Label();
            lbl_note.ID = string.Concat("note_", k);
            lbl_note.Text = dt.Rows[i]["note"].ToString();
            cell.Controls.Add(lbl_note);
            row.Cells.Add(cell);
           
            //添加第5列 Part Order Quantity
            cell = new TableCell();
            Label lbl_partquantity = new Label();
            lbl_partquantity.ID = string.Concat("partquantity_", k);
            lbl_partquantity.Text = dt.Rows[i]["partquantity"].ToString();
            cell.Controls.Add(lbl_partquantity);
            row.Cells.Add(cell);

            //添加第6列 Shipping date
            cell = new TableCell();
            cell.Width = 110;
            TextBox tb_shippingdate = new TextBox();
            tb_shippingdate.Width = 100;
            tb_shippingdate.ID = string.Concat("shippingdate_", k);
            tb_shippingdate.Text = dt.Rows[i]["shippingdate"].ToString();
            cell.Controls.Add(tb_shippingdate);
            row.Cells.Add(cell);

            //添加第7列 Material for Samples
            cell = new TableCell();
            cell.Width = 200;
            Label lbl_procured1 = new Label();
            lbl_procured1.ID = string.Concat("procured1_", k);
            lbl_procured1.Text = "● " + "Procured ";
            cell.Controls.Add(lbl_procured1);
            TextBox tb_procured1 = new TextBox();
            tb_procured1.Width = 100;
            tb_procured1.ID = string.Concat("tbprocured1_", k);
            tb_procured1.Text = dt.Rows[i]["procured1"].ToString();
            cell.Controls.Add(tb_procured1);
            CheckBox chk_procured1 = new CheckBox();
            chk_procured1.ID = string.Concat("chk_procured1", k);
            chk_procured1.Checked = Convert.ToBoolean(int.Parse(dt.Rows[i]["procured1_finish"].ToString()));
            cell.Controls.Add(chk_procured1);
            Label lbl_procured1br = new Label();
            //lbl_br.ID = string.Concat("br_", k);
            lbl_procured1br.Text = "<br/>";
            cell.Controls.Add(lbl_procured1br);

            Label lbl_received1 = new Label();
            lbl_received1.ID = string.Concat("received1_", k);
            lbl_received1.Text = "● " + "Received ";
            cell.Controls.Add(lbl_received1);
            TextBox tb_received1 = new TextBox();
            tb_received1.Width = 100;
            tb_received1.ID = string.Concat("tbreceived1_", k);
            tb_received1.Text = dt.Rows[i]["received1"].ToString();
            cell.Controls.Add(tb_received1);
            CheckBox chk_received1 = new CheckBox();
            chk_received1.ID = string.Concat("chk_received1", k);
            chk_received1.Checked = Convert.ToBoolean(int.Parse(dt.Rows[i]["received1_finish"].ToString()));
            cell.Controls.Add(chk_received1);
            Label lbl_received1br = new Label();
            //lbl_br.ID = string.Concat("br_", k);
            lbl_received1br.Text = "<br/>";
            cell.Controls.Add(lbl_received1br);
            row.Cells.Add(cell);

            //添加第8列 Material for Production
            cell = new TableCell();
            cell.Width = 200;
            Label lbl_procured2 = new Label();
            lbl_procured2.ID = string.Concat("procured2_", k);
            lbl_procured2.Text = "● " + "Procured ";
            cell.Controls.Add(lbl_procured2);
            TextBox tb_procured2 = new TextBox();
            tb_procured2.Width = 100;
            tb_procured2.ID = string.Concat("tbprocured2_", k);
            tb_procured2.Text = dt.Rows[i]["procured2"].ToString();
            cell.Controls.Add(tb_procured2);
            CheckBox chk_procured2 = new CheckBox();
            chk_procured2.ID = string.Concat("chk_procured2", k);
            chk_procured2.Checked = Convert.ToBoolean(int.Parse(dt.Rows[i]["procured2_finish"].ToString()));
            cell.Controls.Add(chk_procured2);
            Label lbl_procured2br = new Label();
            //lbl_br.ID = string.Concat("br_", k);
            lbl_procured2br.Text = "<br/>";
            cell.Controls.Add(lbl_procured2br);

            Label lbl_received2 = new Label();
            lbl_received2.ID = string.Concat("received2_", k);
            lbl_received2.Text = "● " + "Received ";
            cell.Controls.Add(lbl_received2);
            TextBox tb_received2 = new TextBox();
            tb_received2.Width = 100;
            tb_received2.ID = string.Concat("tbreceived2_", k);
            tb_received2.Text = dt.Rows[i]["received2"].ToString();
            cell.Controls.Add(tb_received2);
            CheckBox chk_received2 = new CheckBox();
            chk_received2.ID = string.Concat("chk_received2", k);
            chk_received2.Checked = Convert.ToBoolean(int.Parse(dt.Rows[i]["received2_finish"].ToString()));
            cell.Controls.Add(chk_received2);
            Label lbl_received2br = new Label();
            //lbl_br.ID = string.Concat("br_", k);
            lbl_received2br.Text = "<br/>";
            cell.Controls.Add(lbl_received2br);

            row.Cells.Add(cell);

            //添加第9列 Shiping Notice
            cell = new TableCell();
            cell.Width = 100;
            //Label lbl_exportationmold = new Label();
            //lbl_exportationmold.ID = string.Concat("exportationmold_", k);
            //lbl_exportationmold.Text = dt_tooling.Rows[i]["exportationmold"].ToString();
            //cell.Controls.Add(lbl_exportationmold);
            row.Cells.Add(cell);


            //增加一行
            Table4.Rows.Add(row);
        }
    }

效果见图片所示

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值