Hi,
Here the below code is for dynamically creating textboxs, its creating fine but after user enters some values in textboxs how can i retrive that values?
[code=cpp]
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Collecti ons.Generic;
public partial class _Default : System.Web.UI.P age
{
static int a = 0;
int skillCount = 0;
List<string> skillControlLis t;
int yearsUsedCount = 0;
List<string> yearsUsedContro lList;
int yearsLastUsedCo unt = 0;
List<string> YearsLastUsedUs edControlList;
protected override void LoadViewState(o bject savedState)
{
base.LoadViewSt ate(savedState) ;
skillControlLis t = (List<string>)V iewState["skillControlLi st"];
foreach (string skillYearsId in skillControlLis t)
{
skillCount++;
TextBox skillTxt = new TextBox();
skillTxt.ID = skillYearsId;
//LiteralControl lineBreak = new LiteralControl( "<br />");
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Controls.Add (skillTxt);
tr.Cells.Add(tc );
tblSkills.Rows. Add(tr);
}
yearsUsedContro lList = (List<string>)V iewState["yearsUsedContr olList"];
foreach (string yearsUsedId in yearsUsedContro lList)
{
yearsUsedCount+ +;
TextBox yearsUsedTxt = new TextBox();
yearsUsedTxt.ID = yearsUsedId;
// LiteralControl lineBreak1 = new LiteralControl( "<br />");
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.A dd(yearsUsedTxt );
row.Cells.Add(c ell);
tblYearsUsed.Ro ws.Add(row);
}
YearsLastUsedUs edControlList = (List<string>)V iewState["YearsLastUsedU sedControlList"];
foreach (string yearsLastUsedId in YearsLastUsedUs edControlList)
{
yearsLastUsedCo unt++;
TextBox yearsLastUsedTx t = new TextBox();
yearsLastUsedTx t.ID = yearsLastUsedId ;
// LiteralControl lineBreak1 = new LiteralControl( "<br />");
TableRow yearRow = new TableRow();
TableCell yearCell = new TableCell();
yearCell.Contro ls.Add(yearsLas tUsedTxt);
yearRow.Cells.A dd(yearCell);
tblYearsLastUse d.Rows.Add(year Row);
}
}
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
skillControlLis t = new List<string>();
ViewState["skillControlLi st"] = skillControlLis t;
yearsUsedContro lList = new List<string>();
ViewState["yearsUsedContr olList"] = yearsUsedContro lList;
YearsLastUsedUs edControlList = new List<string>();
ViewState["YearsLastUsedU sedControlList"] = YearsLastUsedUs edControlList;
a = 0;
}
}
protected void addControlButto n_Click(object sender, EventArgs e)
{
a++;
int b = 10;
if (a <= b)
{
skillCount++;
TextBox skillTxt = new TextBox();
//skillTxt.Text = "a new text Box";
skillTxt.ID = "txtSkill" + skillCount.ToSt ring();
// LiteralControl lineBreak = new LiteralControl( "<br />");
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Controls.Add (skillTxt);
tr.Cells.Add(tc );
tblSkills.Rows. Add(tr);
skillControlLis t.Add(skillTxt. ID);
ViewState["skillControlLi st"] = skillControlLis t;
yearsUsedCount+ +;
TextBox yearsUsedTxt = new TextBox();
//yearsUsedTxt.Te xt = "a new text Box";
yearsUsedTxt.ID = "txtYearUse d" + yearsUsedCount. ToString();
// LiteralControl lineBreak1 = new LiteralControl( "<br />");
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.A dd(yearsUsedTxt );
row.Cells.Add(c ell);
tblYearsUsed.Ro ws.Add(row);
yearsUsedContro lList.Add(years UsedTxt.ID);
ViewState["yearsUsedContr olList"] = yearsUsedContro lList;
yearsLastUsedCo unt++;
TextBox yearsLastUsedTx t = new TextBox();
//yearsUsedTxt.Te xt = "a new text Box";
yearsLastUsedTx t.ID = "txtLastYearUse d" + yearsLastUsedCo unt.ToString();
// LiteralControl lineBreak1 = new LiteralControl( "<br />");
TableRow yearRow = new TableRow();
TableCell yearCell = new TableCell();
yearCell.Contro ls.Add(yearsLas tUsedTxt);
yearRow.Cells.A dd(yearCell);
tblYearsLastUse d.Rows.Add(year Row);
YearsLastUsedUs edControlList.A dd(yearsLastUse dTxt.ID);
ViewState["YearsLastUsedU sedControlList"] = YearsLastUsedUs edControlList;
}
else
{
Label1.Text = "no more";
}
}
}[/code]
Here the below code is for dynamically creating textboxs, its creating fine but after user enters some values in textboxs how can i retrive that values?
[code=cpp]
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Collecti ons.Generic;
public partial class _Default : System.Web.UI.P age
{
static int a = 0;
int skillCount = 0;
List<string> skillControlLis t;
int yearsUsedCount = 0;
List<string> yearsUsedContro lList;
int yearsLastUsedCo unt = 0;
List<string> YearsLastUsedUs edControlList;
protected override void LoadViewState(o bject savedState)
{
base.LoadViewSt ate(savedState) ;
skillControlLis t = (List<string>)V iewState["skillControlLi st"];
foreach (string skillYearsId in skillControlLis t)
{
skillCount++;
TextBox skillTxt = new TextBox();
skillTxt.ID = skillYearsId;
//LiteralControl lineBreak = new LiteralControl( "<br />");
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Controls.Add (skillTxt);
tr.Cells.Add(tc );
tblSkills.Rows. Add(tr);
}
yearsUsedContro lList = (List<string>)V iewState["yearsUsedContr olList"];
foreach (string yearsUsedId in yearsUsedContro lList)
{
yearsUsedCount+ +;
TextBox yearsUsedTxt = new TextBox();
yearsUsedTxt.ID = yearsUsedId;
// LiteralControl lineBreak1 = new LiteralControl( "<br />");
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.A dd(yearsUsedTxt );
row.Cells.Add(c ell);
tblYearsUsed.Ro ws.Add(row);
}
YearsLastUsedUs edControlList = (List<string>)V iewState["YearsLastUsedU sedControlList"];
foreach (string yearsLastUsedId in YearsLastUsedUs edControlList)
{
yearsLastUsedCo unt++;
TextBox yearsLastUsedTx t = new TextBox();
yearsLastUsedTx t.ID = yearsLastUsedId ;
// LiteralControl lineBreak1 = new LiteralControl( "<br />");
TableRow yearRow = new TableRow();
TableCell yearCell = new TableCell();
yearCell.Contro ls.Add(yearsLas tUsedTxt);
yearRow.Cells.A dd(yearCell);
tblYearsLastUse d.Rows.Add(year Row);
}
}
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
skillControlLis t = new List<string>();
ViewState["skillControlLi st"] = skillControlLis t;
yearsUsedContro lList = new List<string>();
ViewState["yearsUsedContr olList"] = yearsUsedContro lList;
YearsLastUsedUs edControlList = new List<string>();
ViewState["YearsLastUsedU sedControlList"] = YearsLastUsedUs edControlList;
a = 0;
}
}
protected void addControlButto n_Click(object sender, EventArgs e)
{
a++;
int b = 10;
if (a <= b)
{
skillCount++;
TextBox skillTxt = new TextBox();
//skillTxt.Text = "a new text Box";
skillTxt.ID = "txtSkill" + skillCount.ToSt ring();
// LiteralControl lineBreak = new LiteralControl( "<br />");
TableRow tr = new TableRow();
TableCell tc = new TableCell();
tc.Controls.Add (skillTxt);
tr.Cells.Add(tc );
tblSkills.Rows. Add(tr);
skillControlLis t.Add(skillTxt. ID);
ViewState["skillControlLi st"] = skillControlLis t;
yearsUsedCount+ +;
TextBox yearsUsedTxt = new TextBox();
//yearsUsedTxt.Te xt = "a new text Box";
yearsUsedTxt.ID = "txtYearUse d" + yearsUsedCount. ToString();
// LiteralControl lineBreak1 = new LiteralControl( "<br />");
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.A dd(yearsUsedTxt );
row.Cells.Add(c ell);
tblYearsUsed.Ro ws.Add(row);
yearsUsedContro lList.Add(years UsedTxt.ID);
ViewState["yearsUsedContr olList"] = yearsUsedContro lList;
yearsLastUsedCo unt++;
TextBox yearsLastUsedTx t = new TextBox();
//yearsUsedTxt.Te xt = "a new text Box";
yearsLastUsedTx t.ID = "txtLastYearUse d" + yearsLastUsedCo unt.ToString();
// LiteralControl lineBreak1 = new LiteralControl( "<br />");
TableRow yearRow = new TableRow();
TableCell yearCell = new TableCell();
yearCell.Contro ls.Add(yearsLas tUsedTxt);
yearRow.Cells.A dd(yearCell);
tblYearsLastUse d.Rows.Add(year Row);
YearsLastUsedUs edControlList.A dd(yearsLastUse dTxt.ID);
ViewState["YearsLastUsedU sedControlList"] = YearsLastUsedUs edControlList;
}
else
{
Label1.Text = "no more";
}
}
}[/code]
Comment