如何在html输入的位置添加动态文本框

时间:2015-04-23 14:50:47

标签: c# asp.net .net dynamic-programming

我以字符串格式生成了一个表并添加到正文中

string mid = "<tr class='cart_item'>" +  "<td class='product-remove'>" +

                          " <a href='handler.ashx?id=" + id + "' class='remove' title='Remove this item'>&times;</a>" +

                          "</td>" +

                      " <td class='product-thumbnail'>" +
                      "     <a href='StoreDetails.aspx?id=" + id + "'>" +
              "<img src='" + thumb + "' " +
              "class='attachment-shop_thumbnail wp-post-image' alt='" + pname + "' /></a>                   </td>" +

                      " <td class='product-name'>" +
                      "     <a href='StoreDetails.aspx?id=" + id + "'>"+pname+"</a>                 </td>" +

                      " <td class='product-price'>" +
                      "     <span class='amount'><i class='icon-inr'></i> " + cd.packsize + "</span>                    </td>" +

                      " <td class='product-price'>" +
                      "     <span class='amount'><i class='icon-inr'></i> " + price + "</span>                  </td>" +

                      " <td class='product-quantity'>" +
                      "        <div class='quantity buttons_added'><input value='-' class='minus' type='button'>" +

                  "<input step='1' min='1' name='quantity' value='" + qty + "' title='Qty' class='input-text qty text ' id='txtqty" + cd.id+"' size='4' type='text'>" +

首先,我在html中添加了输入type="text",但现在我想添加asp.net文本框控件

"<input value='+' class='plus' type='button'></div>" +
            //   qty +

                          "</td>" +

                          "<td class='product-subtotal'>" +
                          " <span class='amount'><i class='icon-inr'></i>  " + (Convert.ToDouble(price) * qty) + "</span>                   </td>" +
                      "</tr>";




       //   int qty = ((Dictionary<int, int>)Session["cart"])[id];

          cartInfo.InnerHtml += mid;

1 个答案:

答案 0 :(得分:1)

将PlaceHolder控件放在要渲染表的位置。

在您的ASPX文件中:

<asp:PlaceHolder ID="ph" runat="server" />

在ASPX.CS文件后面的代码中:

Literal loLit1 = new Literal();
    loLit1.Text = "String above the Quantity Textbox";

    ph.Controls.Add(loLit1);

    TextBox loTxt = new TextBox();
    loTxt.Attributes.Add("step", "1");
    loTxt.Attributes.Add("min", "1");
    loTxt.Attributes.Add("name", "quantity");
    loTxt.Text = "10";
    loTxt.ToolTip = "Qty";
    loTxt.ID = "txtqty";

    ph.Controls.Add(loTxt);

    Literal loLit2 = new Literal();
    loLit2.Text = "String After the Quantity Textbox";
    ph.Controls.Add(loLit2);