The problem I am facing is that the user can add one row easily, but any attempts to add rows after that overwrites the previously added row hence displaying only two rows on the page regardless of the number of rows added.
I have been scratching my head on this for a while now and any help would really be appreciated.
Thanks.
HTML code:
| Loan Type | Amount Owing | Monthly Repayments |
onclick="iBtnRemoveRow_Click" /> |
Back End Code:
protected void iBtnAddRow_Click(object sender, ImageClickEventArgs e)
{
int iIndex = Convert.ToInt32(Session["iKeyIndex"]);
iIndex = iIndex+1;
//Instantiate and create new items
TableRow rTableRow = new TableRow();
TableCell cTableCellLoanTypeDropDown = new TableCell();
TableCell cTableCellBalance = new TableCell();
TableCell cTableCellMonthlyRepayments = new TableCell();
HtmlSelect hSelect = new HtmlSelect();
TextBox txtBalance = new TextBox();
TextBox txtRepayments = new TextBox();
try
{
///******************** First we create the drop down menu *******************************///
hSelect.Attributes.Add("name", "ctl00_ContentPlaceHolder1loanType" + iIndex);
hSelect.Attributes.Add("id", "ctl00_ContentPlaceHolder1_loanType" + iIndex);
hSelect.Attributes.Add("class", "txtNormalDrp");
hSelect.Attributes.Add("runat", "server");
//Add the selection items to hSelect
ListItem lst = new ListItem("Please Select", "");
lst.Attributes.Add("Selected", "Selected");
hSelect.Items.Add(lst);
ListItem lst1 = new ListItem("Home Loan", "Home Loan");
hSelect.Items.Add(lst1);
ListItem lst2 = new ListItem("Investment Loan", "Investment Loan");
hSelect.Items.Add(lst2);
ListItem lst3 = new ListItem("Credit Card", "Credit Card");
hSelect.Items.Add(lst3);
ListItem lst4 = new ListItem("Personal Loan", "Personal Loan");
hSelect.Items.Add(lst4);
ListItem lst5 = new ListItem("Store Cards", "Store Cards");
hSelect.Items.Add(lst5);
ListItem lst6 = new ListItem("Tax Debt", "Tax Debt");
hSelect.Items.Add(lst6);
ListItem lst7 = new ListItem("Other", "Other");
hSelect.Items.Add(lst7);
//Assign the drop down to the first cell
cTableCellLoanTypeDropDown.Controls.Add(hSelect);
///**************************************************************************************///
///*************** Second we create the Text box for Balance*****************************///
txtBalance.Attributes.Add("class", "txtBalrepayments");
txtBalance.Attributes.Add("name", "balance" + iIndex);
txtBalance.Attributes.Add("id", "balance" + iIndex);
txtBalance.Attributes.Add("onfocusout", "fcnAddTotals();");
txtBalance.Attributes.Add("onkeypress", "return numbersonly(event, false)");
//Assign the textbox to the second column
cTableCellBalance.Controls.Add(txtBalance);
///**************************************************************************************///
///*************** Second we create the Text box for Monthly Repayments******************///
txtRepayments.Attributes.Add("class", "txtBalrepayments");
txtRepayments.Attributes.Add("name", "mRepayments" + iIndex);
txtRepayments.Attributes.Add("id", "mRepayments" + iIndex);
txtRepayments.Attributes.Add("onfocusout", "fcnAddTotals();");
txtRepayments.Attributes.Add("onkeypress", "return numbersonly(event, false)");
//Assign the textbox to the third column
cTableCellMonthlyRepayments.Controls.Add(txtRepayments);
///**************************************************************************************///
///************************************ FINALLY *****************************************///
//Add the Row to the table
//tblLoanTypes.Rows.Insert(iIndex, rTableRow);
tblLoanTypes.Rows.AddAt((tblLoanTypes.Rows.Count-1),rTableRow);
//Add the cells and rows to the table: tblLoanTypes
rTableRow.Cells.Add(cTableCellLoanTypeDropDown);
rTableRow.Cells.Add(cTableCellBalance);
rTableRow.Cells.Add(cTableCellMonthlyRepayments);
//Increase the index and save it to the session variable
Session["iKeyIndex"] = iIndex;
}
catch (Exception sError)
{
string sErr = sError.Message;
}
finally
{
//Flush all the declarations
hSelect.Dispose();
txtBalance.Dispose();
txtRepayments.Dispose();
cTableCellLoanTypeDropDown.Dispose();
cTableCellBalance.Dispose();
cTableCellMonthlyRepayments.Dispose();
rTableRow.Dispose();
}
}
protected void iBtnRemoveRow_Click(object sender, ImageClickEventArgs e)
{
}
Sam HobbsPosted Mar 22, 2010, 8:53 PM