Click here to Skip to main content
15,911,132 members
Home / Discussions / C#
   

C#

 
AnswerRe: Nested DataGridView Pin
Xmen Real 17-Mar-10 20:45
professional Xmen Real 17-Mar-10 20:45 
QuestionSerial port open is not throwing exception Pin
greg_martin17-Mar-10 11:13
greg_martin17-Mar-10 11:13 
AnswerRe: Serial port open is not throwing exception Pin
Richard MacCutchan17-Mar-10 12:24
mveRichard MacCutchan17-Mar-10 12:24 
GeneralRe: Serial port open is not throwing exception Pin
greg_martin17-Mar-10 13:42
greg_martin17-Mar-10 13:42 
AnswerRe: Serial port open is not throwing exception Pin
PIEBALDconsult17-Mar-10 13:02
mvePIEBALDconsult17-Mar-10 13:02 
GeneralRe: Serial port open is not throwing exception Pin
Luc Pattyn17-Mar-10 13:43
sitebuilderLuc Pattyn17-Mar-10 13:43 
QuestionDataGridView.DataSource WM_MOUSEMOVE [modified] Pin
DaveyM6917-Mar-10 10:55
professionalDaveyM6917-Mar-10 10:55 
QuestionDynamically Add Rows to html table from code behind [modified] Pin
Ali Rashid17-Mar-10 8:56
Ali Rashid17-Mar-10 8:56 
Hi Guys!
I am in a bit of a Dilemma here and need some help. I have a table that has a row and three columns which are showed to the user after the page loads. There is a button which calls a code behind function to add a new row. The first time the user clicks, the row is added properly, no problem. The second time however, the row is not added but the previous row that was added is updated with the new id/name etc. Also the second time, the drop down menu gives an error which is quiet ridiculous, something to do with accessing innerHtml of the drop down menu when I am not even asking the compiler to assign anything of that sort. Please have a look and let me know where the problem is which my brain cells are failing to recognise.
Note: I have tried all the different methods to add the row for example table.Rows.Insert(index,htmlRow) etc.
Thanks is Advance.

Below id my code for reference:

=============================
Front End [HTML - Table only]
=============================
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table cellpadding="3" cellspacing="3" runat="server">
<tr>
<td style="font-family:Courier New; font-size:12pt;"><b>Loan Type</b></td>
<td style="font-family:Courier New; font-size:12pt;"><b>Amount Owing</b></td>
<td style="font-family:Courier New; font-size:12pt;"><b>Monthly Repayments</b></td>
</tr>
</table>
<table cellpadding="3" cellspacing="3" id="tblLoanTypes" runat="server">
<tr>
<td width="33%">
<select name="loanType1" id="loanType1" class="txtNormalDrp" runat="server">
<option value="" selected="selected">Please Select</option>
<option value="Home Loan">Home Loan</option>
<option value="Investment Loan">Investment Loan</option>
<option value="Credit Card">Credit Card</option>
<option value="Personal Loan">Personal Loan</option>
<option value="Store Cards">Store Cards</option>
<option value="Tax Debt">Tax Debt</option>
<option value="Other">Other</option>
</select>
</td>
<td width="33%"><input type="text" class="txtBalrepayments" name="balance1" id="balance1" onfocusout="fcnAddTotals();" onkeypress="return numbersonly(event, false)" /></td>
<td><input type="text" class="txtBalrepayments" name="mRepayments1" id="mRepayments1" onfocusout="fcnAddPayments();" onkeypress="return numbersonly(event, false)" /></td>
</tr>
</table>
<table>
<tr>
<td><asp:ImageButton ID="iBtnAddRow" runat="server"
ImageUrl="images/btnAddRows.jpg" onclick="iBtnAddRow_Click" />&nbsp;&nbsp;&nbsp;<asp:ImageButton
ID="iBtnRemoveRow" runat="server" ImageUrl="images/btnRemoveRows.jpg"
onclick="iBtnRemoveRow_Click" />
</td>
</tr>
</table>
</asp:Content>

======================
Code Behind [.cs File]
======================
protected void iBtnAddRow_Click(object sender, ImageClickEventArgs e)
{
int iIndex = Convert.ToInt32(Session["iKeyIndex"]);
iIndex = iIndex+1;

//Instantiate and create new items
HtmlTableRow rTableRow = new HtmlTableRow();
HtmlTableCell cTableCellLoanTypeDropDown = new HtmlTableCell();
HtmlTableCell cTableCellBalance = new HtmlTableCell();
HtmlTableCell cTableCellMonthlyRepayments = new HtmlTableCell();
HtmlSelect hSelect = new HtmlSelect();
TextBox txtBalance = new TextBox();
TextBox txtRepayments = new TextBox();

try
{
///******************** First we create the drop down menu *******************************///
hSelect.Attributes.Add("name", "loanType" + iIndex);
hSelect.Attributes.Add("id", "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((tblLoanTypes.Rows.Count+1), rTableRow);
tblLoanTypes.Rows.Add(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)
{
//Functions._sendEmail(Error generating Rows", System.Configuration.ConfigurationManager.AppSettings["sWebAdminEmail"].ToString(),
// "An error has occured generating Dynamic Rows on Error: " + sError.Message);
}
finally
{
//Flush all the declarations
hSelect.Dispose();
txtBalance.Dispose();
txtRepayments.Dispose();
cTableCellLoanTypeDropDown.Dispose();
cTableCellBalance.Dispose();
cTableCellMonthlyRepayments.Dispose();
rTableRow.Dispose();
}
}



P.S: Sorry but my previous post caused some issue to the forum. I appologise for any inconvenience caused.
Thanks
modified on Wednesday, March 17, 2010 3:16 PM

AnswerRe: Dynamically Add Rows to html table from code behind Pin
Dave Kreskowiak17-Mar-10 9:12
mveDave Kreskowiak17-Mar-10 9:12 
GeneralRe: Dynamically Add Rows to html table from code behind Pin
Ali Rashid17-Mar-10 9:18
Ali Rashid17-Mar-10 9:18 
AnswerRe: Dynamically Add Rows to html table from code behind Pin
Saksida Bojan17-Mar-10 9:13
Saksida Bojan17-Mar-10 9:13 
AnswerRe: Dynamically Add Rows to html table from code behind Pin
OriginalGriff17-Mar-10 9:55
mveOriginalGriff17-Mar-10 9:55 
GeneralRe: Dynamically Add Rows to html table from code behind Pin
Saksida Bojan17-Mar-10 9:57
Saksida Bojan17-Mar-10 9:57 
AnswerRe: Dynamically Add Rows to html table from code behind Pin
PunkIsNotDead17-Mar-10 14:57
PunkIsNotDead17-Mar-10 14:57 
GeneralRe: Dynamically Add Rows to html table from code behind Pin
Ali Rashid18-Mar-10 2:42
Ali Rashid18-Mar-10 2:42 
QuestionPST file processing Pin
heretic61917-Mar-10 7:42
heretic61917-Mar-10 7:42 
QuestionBest Practice Suggestions for Mapping ClassA.Value to ClassB.Property? Pin
Matthew Klein17-Mar-10 7:18
Matthew Klein17-Mar-10 7:18 
AnswerRe: Best Practice Suggestions for Mapping ClassA.Value to ClassB.Property? Pin
#realJSOP17-Mar-10 7:39
professional#realJSOP17-Mar-10 7:39 
AnswerIf you want the OO way Pin
Ennis Ray Lynch, Jr.17-Mar-10 11:34
Ennis Ray Lynch, Jr.17-Mar-10 11:34 
QuestionIllegal cross thread exception in Invoke method Pin
yeah100017-Mar-10 4:21
yeah100017-Mar-10 4:21 
AnswerRe: Illegal cross thread exception in Invoke method Pin
Abhinav S17-Mar-10 4:51
Abhinav S17-Mar-10 4:51 
GeneralRe: Illegal cross thread exception in Invoke method Pin
AspDotNetDev17-Mar-10 12:30
protectorAspDotNetDev17-Mar-10 12:30 
GeneralRe: Illegal cross thread exception in Invoke method Pin
Luc Pattyn17-Mar-10 12:52
sitebuilderLuc Pattyn17-Mar-10 12:52 
AnswerRe: Illegal cross thread exception in Invoke method Pin
Dave Kreskowiak17-Mar-10 4:59
mveDave Kreskowiak17-Mar-10 4:59 
GeneralRe: Illegal cross thread exception in Invoke method [modified] Pin
yeah100017-Mar-10 5:07
yeah100017-Mar-10 5:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.