【问题标题】:How to add dynamic textbox in the place of html input如何在html输入的位置添加动态文本框
【发布时间】:2015-07-01 20:27:09
【问题描述】:

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

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;

【问题讨论】:

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


    【解决方案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);
    

    【讨论】:

    • 感谢您的帮助,但此代码仅生成文本框并添加占位符。我将如何呈现表格并在其中添加动态文本框
    • 在您的问题中,您提供了两个字符串和放置在这两个字符串之间的文本框。在我的回答中,我已经提到了loLit1.Text = mid (1st string of your question)loLit2.Text = 2nd String (After your quantity textbox)。够公平吗?
    • 我已经使用了上面的代码,但是占位符显示字符串和控件以不同的格式分开
    • 你能给我看屏幕截图以便更好地理解吗?您可以在任何免费图片上传网站上传屏幕截图并在此处分享该链接。
    猜你喜欢
    • 1970-01-01
    • 2018-11-30
    • 2010-12-08
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多