Saturday, March 24, 2012

UpdatePanel and Dynamic populated table

My control builds a table dynamically [some subscription rows]

The table is placed inside and update panel:

<atlas:UpdatePanel ID="upBrowse" runat="server" Mode="Conditional" RenderMode="Inline"> <Triggers> <atlas:ControlEventTrigger ControlID="btnDelete" EventName="Click" /> <atlas:ControlEventTrigger ControlID="btnOK" EventName="Click" /> </Triggers> <ContentTemplate> <asp:Table ID="tblSubscriptions" runat="server" CellPadding="1" CellSpacing="1" Style="position: relative" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" EnableViewState="true"> </asp:Table> <br /> <asp:Button ID="btnAdd" Text="Add" runat="server" OnClick="btnAdd_Click" /> <asp:Button ID="btnDelete" Text="Delete" runat="server" OnClick="btnDelete_Click" /> </ContentTemplate> </atlas:UpdatePanel>

When the table gets populated, there is a checkbox for each row to select the subscriptions to be deleted.

There is a Delete Button and the task is to select all the checked rows and delete them.

My problem is that on the trip back, handling the delete button 'btnDelete_Click' I cannot iterate the table programmatically because there are no rows:

foreach (TableRow rowin tblSubscriptions.Rows) --> no rows

What is wrong?

Thx,

Uri

Can you show a some code how you add dynamic rows? Just as an idea - maybe HtmlTableRow instead TableRow? You can use Repeater with checkboxes instead your table, and you will receive selected values in the Form collection...
foreach (Subscription oSubin oSubscriptions) { count++;if ((int)oSub.GetFieldValue("SystemID") == _systemId) { TableRow row =new TableRow();if (bInStyleAlt) { row.ApplyStyle(styleAlt); bInStyleAlt =false; }else { row.ApplyStyle(styleNormal); bInStyleAlt =true; } CheckBox box =new CheckBox(); box.ID ="chkSub_" + oSub.SubscriptionId; box.Checked =false; TableCell cellChk =new TableCell(); cellChk.Controls.Add(box); row.Cells.Add(cellChk);

Interesting points:

I am able to manipulate other elements inside the update panel (like textboxes) if these are not inserted dynamically.

Let me try HtmlTableRow or the repeater

No comments:

Post a Comment