HI ,
I have improved my solution, by this solution you can create as many as
you want of text box and u can retrieve the data from it . and it also can be use this code on various Controls
just let me know your feedback .
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="show data"
onclick="Button2_Click" />
<div id="DivContent" runat="server">
</div>
</form>
</body>
Code behind :
protected System.Web.UI.WebControls.TextBox txtSkill;
protected System.Web.UI.WebControls.TextBox txtVersion;
protected void Page_Load(object sender, EventArgs e)
{
}
int countTimes = 0;
protected void Button1_Click(object sender, EventArgs e)
{
if (ViewState["countTimes"] == null)
{
countTimes = 1;
}
else
{
countTimes = Convert.ToInt32(ViewState["countTimes"]);
}
for (int i = 0; i < countTimes; i++)
{
txtSkill = new TextBox();
txtSkill.ID = "txtSkill" + i;
txtVersion = new TextBox();
txtVersion.ID = "txtVersion" + i;
form1.Controls.Add(txtSkill);
form1.Controls.Add(txtVersion);
}
countTimes = countTimes + 1;
ViewState.Add("countTimes", countTimes);
}
protected void Button2_Click(object sender, EventArgs e)
{
if (ViewState["countTimes"] == null)
{
countTimes = 1;
}
else
{
countTimes = Convert.ToInt32(ViewState["countTimes"]);
}
for (int i = 0; i < countTimes -1; i++)
{
txtSkill = new TextBox();
txtSkill.ID = "txtSkill" + i;
txtVersion = new TextBox();
txtVersion.ID = "txtVersion" + i;
form1.Controls.Add(txtSkill);
form1.Controls.Add(txtVersion);
}
string storeToDbValueOne = ""; string storeToDbValueTwo = "";
for (int i = 0; i < countTimes; i++)
{
storeToDbValueOne += Request.Form["txtSkill" + i];
storeToDbValueOne += Request.Form["txtVersion" + i];
}
Response.Write("<script>alert('"+storeToDbValueOne +" "+storeToDbValueTwo+"')</script>");
}
Best regards
M.Mitwalli