how to add row in a table dynamically in .net with C# one by one on button click

Jan 17 2011 3:54 AM

Hello,
I want to add rows and cell in table whitch already contain 1 row and in that cell want to add a usercontrol on each click of button i have done the following coding but the problem is that, the  user control is added on first click but on next click the user control is added in the same row disappering the first one . Cant i add the user control one after other on the same btn click.
plz help..
<
asp:Panel ID="pnlOQualification" runat="server">
<asp:UpdatePanel ID="updpnlOQualification" runat="server">
<ContentTemplate>
<table border="0" cellpadding="1" cellspacing="3" width="98%">
<tr>
<td valign="top" class="hometext10" colspan="2" id="td5" runat="server">
<asp:UpdatePanel ID="updpnlOthrEdu" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table border="0" cellpadding="1" cellspacing="3" width="100%" id="tblOtherQualification"
runat="server">
<tr>
<td align="left" width="34%">
Other Qualification (if any)
</td>
<td align="left" width="66%">
<asp:ImageButton ID="AddQualification" runat="server" ImageUrl="~/images/plus_sign.gif"
OnClick="AddQualification_Click" />
</td>
</tr>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="AddQualification" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
protected void AddQualification_Click(object sender, ImageClickEventArgs e)
{
try
{
HtmlTableRow htRow = new HtmlTableRow();
HtmlTableCell htCell = new HtmlTableCell();
htCell.Align =
"Left";
htCell.ColSpan = 2;
Control ConOtherQuali = LoadControl("~/userControll/OtherQualification.ascx");
htCell.Controls.Add(ConOtherQuali);
htRow.Cells.Add(htCell);
tblOtherQualification.Rows.Add(htRow);
}
catch (Exception ex)
{
throw ex;
}
}

Answers (1)