问题
I had generate a table in a string format and added in the body
string mid = "<tr class='cart_item'>" + "<td class='product-remove'>" +
" <a href='handler.ashx?id=" + id + "' class='remove' title='Remove this item'>×</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'>" +
first here, I have added the input type="text" in html, but now I want to add asp.net textbox control
"<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:
Take a PlaceHolder control where you want to render table.
In your ASPX file:
<asp:PlaceHolder ID="ph" runat="server" />
In code behind ASPX.CS file:
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);
来源:https://stackoverflow.com/questions/29827063/how-to-add-dynamic-textbox-in-the-place-of-html-input