如何添加动态文本框在HTML输入的地方(How to add dynamic textbox in

2019-10-22 18:33发布

我曾在一个字符串格式生成一个表,并在人体补充

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'>" +

先在这里,我已经添加了输入type="text"在HTML中,但现在我想补充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;

Answer 1:

就拿要绘制表的占位符控制。

在您的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);


文章来源: How to add dynamic textbox in the place of html input