這裏是我的代碼來創建動態textboxes..I要插入這些值到數據庫如何插入動態創建文本框的值到數據庫
我需要插入動態創建的文本框值database.how我可以做that..i是新的ASP.NET
標記:
<div>
<asp:Panel ID="Panel1" runat="server" Width="300px" />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
代碼隱藏:
protected void Page_load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//Remove the session when first time page loads.
Session.Remove("clicks");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int rowCount = 0;
//initialize a session.
rowCount = Convert.ToInt32(Session["clicks"]);
rowCount++;
//In each button clic save the numbers into the session.
Session["clicks"] = rowCount;
//Create the textboxes and labels each time the button is clicked.
for (int i = 0; i < rowCount; i++)
{
TextBox TxtBoxU = new TextBox();
Label lblU = new Label();
TxtBoxU.ID = "TextBoxU" + i.ToString();
lblU.ID = "LabelU" + i.ToString();
lblU.Text = "Category Name " + (i + 1).ToString() + " : ";
//Add the labels and textboxes to the Panel.
Panel1.Controls.Add(lblU);
Panel1.Controls.Add(TxtBoxU);
}
}
你正在使用哪個數據庫,以及如何與它進行通信? – muddymess 2014-11-03 09:35:59
我正在使用MS SQL服務器數據庫.. – 2014-11-03 09:40:04
我的表名稱是Category和字段是CategoryID,CategoryName – 2014-11-03 09:40:36