Hide deleted row, from DataList without rebinding the DataSource

Betari

New Member
Please consider these operations -[*]Bind a list of files in a DataList.[*]Once the user clicks delete LinkButton, delete the file, inItemCommandEvent.[*]Since rebinding whole data is inefficient, I am simply hidingdeleted row.Following code displays files in a DataList. There is a delete button beside each row.\[code\]<asp:DataList ID="DataList1" OnItemCommand="DataList1_ItemCommand" runat="server"> <ItemTemplate> <tr> <asp:Label Text='<%# Eval("ContainingFolder") as string + "\\" + Eval("FileName") as string %>' Visible="false" ID="lblFullPath" runat="server" /> <td><%# Eval("FileName") %></td> <td><%# Eval("ContainingFolder") %></td> <td><%# Eval("FileSize") %></td> <td><%# Eval("Modified") %></td> <td> <asp:LinkButton Text="Delete" ID="linkDelete" runat="server" /> </td> </tr> </ItemTemplate></asp:DataList>\[/code\]In ItemCommand Event Handler this code deletes the selected file from this list.\[code\]protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e){ if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) return; var selectedItem = e.Item.FindControl("lblFullPath") as Label; e.Item.Visible = false; //doesn't work File.Delete(selectedItem.Text);}\[/code\]However e.Item.Visible = false does not hides the row.As a workaround found here, How to hide an item in datalistI have wrapped contents inside a placeholder control.\[code\]<ItemTemplate> <asp:PlaceHolder ID="ph1" runat="server"> <%--wrapped content--%> </asp:PlaceHolder></ItemTemplate>\[/code\]And hiding the placeholder control -\[code\]protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e){ if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) return; var selectedItem = e.Item.FindControl("lblFullPath") as Label; //e.Item.Visible = false; e.Item.FindControl("ph1").Visible = false; File.Delete(selectedItem.Text);}\[/code\]\[quote\] Generally in asp.net hiding parent control hides all of its child controls.\[/quote\]But I am not able to understand, \[quote\] Why hiding the parent control e.Item doesn't hide its containing elements, in case of DataList ? Can you please advise. \[/quote\]Thank you for your help.
 
Back
Top