<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div class="box-container">
<div class="box-left">
<asp:Repeater ID="RepeaterEmployement"
runat="server"
OnItemCommand="RepeaterEmployement_ItemCommand">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
Highest degree
</td>
</tr>
<tr>
<td>
Employment
status
</td>
<td>
<asp:TextBox ID="txtEmployeeName" runat="server" CssClass="txtbox" Text='<%# DataBinder.Eval(Container.DataItem,
"EmployeeName") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
years of
experience
</td>
<td>
<asp:TextBox ID="txtYearofExp"
runat="server"
CssClass="txtbox"
Text='<%# DataBinder.Eval(Container.DataItem,
"YearofExp") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td>
current
employer
</td>
<td>
<asp:TextBox ID="txtPositionheld"
runat="server"
CssClass="txtbox"
Text='<%# DataBinder.Eval(Container.DataItem,
"PosisitonHeld") %>'></asp:TextBox></li>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnAddAnother"
Font-Bold="true"
runat="server"
Text='<%# DataBinder.Eval(Container.DataItem,
"Button") %>'
CommandName='<%# DataBinder.Eval(Container.DataItem,
"Button") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</div>
<div class="box-right">
<asp:Repeater ID="RepeaterEducational"
runat="server"
OnItemCommand="RepeaterEducational_ItemCommand">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
School /
Institute*
</td>
</tr>
<tr>
<td>
Title
</td>
<td>
<asp:TextBox ID="txtEducationalTitle"
runat="server"
CssClass="txtbox"
Text='<%# DataBinder.Eval(Container.DataItem,
"Title") %>'></asp:TextBox></li>
</td>
</tr>
<tr>
<td>
Previous
employment?*
</td>
<td>
<asp:DropDownList ID="ddlCity"
CssClass="styled"
runat="server">
<asp:ListItem Value="0" Text="--Select--"></asp:ListItem>
<asp:ListItem Value="1" Text="Yes"></asp:ListItem>
<asp:ListItem Value="2" Text="No"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Current title
</td>
<td>
<asp:TextBox ID="txtHighestdegree"
runat="server"
CssClass="txtbox"
Text='<%# DataBinder.Eval(Container.DataItem,
"Degree") %>'></asp:TextBox></li>
</td>
</tr>
<tr>
<td>
Number
</td>
<td>
<asp:TextBox ID="txtUniversity"
runat="server"
CssClass="txtbox"
Text='<%# DataBinder.Eval(Container.DataItem,
"University") %>'></asp:TextBox></li>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnAddAnother"
Font-Bold="true"
runat="server"
Text='<%# DataBinder.Eval(Container.DataItem,
"Button") %>'
CommandName='<%# DataBinder.Eval(Container.DataItem,
"Button") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</div>
</div>
</form>
</body>
</html>
public partial class WebForm2 :
System.Web.UI.Page
{
DataSet dsEmployement, dsEducational = null; //dummy dataset use
for repeater
DataTable tbEmployement, tbEducational = null; //dummy table for
dataset
protected void
Page_Load(object sender, EventArgs e)
{
#region Dynamic Field generation
//Intitalization
dsEducational = new DataSet();
tbEducational = new DataTable();
dsEmployement = new DataSet();
tbEmployement = new DataTable();
//Only first time of page load
if (!Page.IsPostBack)
{
AddEducationalColumns();
AddEmployementColumns();
//Add dummy row to table
tbEducational.Rows.Add("", "", "",
"+");
tbEmployement.Rows.Add("", "", "",
"+");
BindWithEducationalRepeater();
BindWithEmployementRepeater();
}
#endregion
}
#region
Dynamic Field generation helper
private void
AddEducationalColumns()
{
//Add 3 dummy coloumn, this can be increase on our need
basis
tbEducational.Columns.Add("Title");
tbEducational.Columns.Add("Degree");
tbEducational.Columns.Add("University");
tbEducational.Columns.Add("Button");
}
private void
AddEmployementColumns()
{
//Add 3 dummy coloumn, this can be increase on our need
basis
tbEmployement.Columns.Add("EmployeeName");
tbEmployement.Columns.Add("YearofExp");
tbEmployement.Columns.Add("PosisitonHeld");
tbEmployement.Columns.Add("Button");
}
protected void
RepeaterEducational_ItemCommand(object source, RepeaterCommandEventArgs e)
{
int Total = RepeaterEducational.Items.Count; //get total items in repeater
if (e.CommandName == "+")
{
Total = Total + 1; //increase 1 because of add
AddEducationalColumns();
foreach
(RepeaterItem item in
RepeaterEducational.Items)
{
//getting the values of user entered fields
string title = ((TextBox)item.FindControl("txtEducationalTitle")).Text;
string
degree = ((TextBox)item.FindControl("txtHighestdegree")).Text;
string University = ((TextBox)item.FindControl("txtUniversity")).Text;
Button btnAdd = ((Button)item.FindControl("btnAddAnother"));
//now change button text to remove, and save
user entered values in table
tbEducational.Rows.Add(title, degree, University, "x");
}
//Add dummy row, because we need to increase
tbEducational.Rows.Add("", "",
"", "+");
BindWithEducationalRepeater();
}
else if
(e.CommandName == "x")
{
Total = Total - 1;
tbEducational.Columns.Add("Title");
tbEducational.Columns.Add("Degree");
tbEducational.Columns.Add("University");
tbEducational.Columns.Add("Button");
foreach (RepeaterItem
item in RepeaterEducational.Items)
{
Button btnAdd = ((Button)item.FindControl("btnAddAnother"));
if (btnAdd != e.CommandSource) //the current row on which user click will removed
{
string EducationalTitle = ((TextBox)item.FindControl("txtEducationalTitle")).Text;
string Highestdegree = ((TextBox)item.FindControl("txtHighestdegree")).Text;
string University = ((TextBox)item.FindControl("txtUniversity")).Text;
if (btnAdd.Text == "x")
{
tbEducational.Rows.Add(EducationalTitle, Highestdegree, University, "x");
}
else
{
tbEducational.Rows.Add(EducationalTitle, Highestdegree, University, "+");
}
}
}
BindWithEducationalRepeater();
}
}
protected void
RepeaterEmployement_ItemCommand(object source, RepeaterCommandEventArgs e)
{
int Total = RepeaterEmployement.Items.Count; //get total items in repeater
if (e.CommandName == "+")
{
Total = Total + 1; //increase
1 because of add
AddEmployementColumns();
foreach (RepeaterItem
item in RepeaterEmployement.Items)
{
//getting the values of user entered fields
string
EmployeeName = ((TextBox)item.FindControl("txtEmployeeName")).Text;
string YearofExp = ((TextBox)item.FindControl("txtYearofExp")).Text;
string Positionheld = ((TextBox)item.FindControl("txtPositionheld")).Text;
Button btnAdd = ((Button)item.FindControl("btnAddAnother"));
//now change button text to remove, and save
user entered values in table
tbEmployement.Rows.Add(EmployeeName, YearofExp, Positionheld, "x");
}
//Add dummy row, because we need to increase
tbEmployement.Rows.Add("", "", "",
"+");
BindWithEmployementRepeater();
}
else if
(e.CommandName == "x")
{
Total = Total - 1;
tbEmployement.Columns.Add("EmployeeName");
tbEmployement.Columns.Add("YearofExp");
tbEmployement.Columns.Add("PosisitonHeld");
tbEmployement.Columns.Add("Button");
foreach (RepeaterItem
item in RepeaterEmployement.Items)
{
Button btnAdd = ((Button)item.FindControl("btnAddAnother"));
if (btnAdd != e.CommandSource) //the current row on which user click will removed
{
string EmployeeName = ((TextBox)item.FindControl("txtEmployeeName")).Text;
string
YearofExp = ((TextBox)item.FindControl("txtYearofExp")).Text;
string Positionheld = ((TextBox)item.FindControl("txtPositionheld")).Text;
if (btnAdd.Text == "x")
{
tbEmployement.Rows.Add(EmployeeName, YearofExp, Positionheld, "x");
}
else
{
tbEmployement.Rows.Add(EmployeeName, YearofExp, Positionheld, "+");
}
}
}
BindWithEmployementRepeater();
}
}
private void
BindWithEducationalRepeater()
{
//add this table to dataset
dsEducational.Tables.Add(tbEducational);
//bind this dataset to repeater
RepeaterEducational.DataSource = dsEducational;
RepeaterEducational.DataBind();
}
private void
BindWithEmployementRepeater()
{
//add this table to dataset
dsEmployement.Tables.Add(tbEmployement);
//bind this dataset to repeater
RepeaterEmployement.DataSource = dsEmployement;
RepeaterEmployement.DataBind();
}
#endregion
}
------------------------------------------Get Repeater value-----------------
------------------------------------------Get Repeater value-----------------
//get the RepeaterEmployement value
foreach (RepeaterItem
item in RepeaterEducational.Items)
{
educationList.Add(new EducationBL { Highestdegree = ((TextBox)item.FindControl("txtHighestdegree")).Text,
Educationtitle = ((TextBox)item.FindControl("txtEducationalTitle")).Text, University
= ((TextBox)item.FindControl("txtUniversity")).Text });
}
//get the RepeaterEmployement value
foreach (RepeaterItem
item in RepeaterEmployement.Items)
{
employementList.Add(new EmployementBL { Employername = ((TextBox)item.FindControl("txtEmployeeName")).Text,
Lastpositionheld = ((TextBox)item.FindControl("txtYearofExp")).Text, Yearsofservice =
((TextBox)item.FindControl("txtPositionheld")).Text });
}