<fieldset style="width:80%; float:left">
    <legend>计算成本预算</legend>
     <table id="cost" class="zifei" style="margin-left:50px">
         <tr><th>成本类别名称</th><th>价格/人</th><th>详情/备注</th><th></th></tr>
         <tr>
            <td>
                <asp:TextBox ID="txtNamtCostType" runat="server"></asp:TextBox></td>
            <td>
                <asp:TextBox ID="txtPriceCost" runat="server" Width="50px"></asp:TextBox></td>
            <td><asp:TextBox ID="txtNoteCost" runat="server"></asp:TextBox></td>
            <td><asp:Button Text="删除" runat="server" ID="btnCostDelete" 
                    onclick="btnCostDelete_Click" /></td></tr>
         </table>
         <div style="width:150px; float:right; margin-top:10px; margin-bottom:10px">
            <asp:Button ID="btn_AddCostNew" Text="添加新成本" runat="server" 
                 onclick="btn_AddCostNew_Click" /></div>
            <div style="width:150px; float:right; margin-top:10px; margin-bottom:10px">成本合计:<asp:Label runat="server" ID="lbCost" Text=""></asp:Label></div>
麻烦问下各位大哥 如果我想在点击“添加新成本”按钮的时候 动态添加一条下面TR里面的控件,该如何在CS代码里面写。不用JS写。求告知
  <tr>
            <td>
                <asp:TextBox ID="txtNamtCostType" runat="server"></asp:TextBox></td>
            <td>
                <asp:TextBox ID="txtPriceCost" runat="server" Width="50px"></asp:TextBox></td>
            <td><asp:TextBox ID="txtNoteCost" runat="server"></asp:TextBox></td>
            <td><asp:Button Text="删除" runat="server" ID="btnCostDelete" 
                    onclick="btnCostDelete_Click" /></td>
</tr>    </fieldset> 

解决方案 »

  1.   

    asp.net在动态添加控件上要考虑状态问题,这个很麻烦,实际应用中还是客户端添加更多些
      

  2.   

    如果你觉得麻烦,最简单的办法是开始把控件放好,但Visible = false,点击按钮的时候让它Visible = true
      

  3.   

    在asp.net上动态生成控件不像winform那么容易控制 因为web页面有好几种布局方式 还要考试这个
    再一个就是控制的大小`位置 颜色什么的 最麻烦的就是你动态添加了控件以后 跟数据库怎么连上去`字段对应上去啊 动态生成字段没问题 但是在web
    上就要考虑到安全问题了` 这样的很容易被攻击`
      

  4.   

    用 jquery 方便 简单