code_junkie

Does anyone know of a way of hiding a column in an asp.net listview?

Nov 10th, 2011
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. <asp:ListView ID="ListView1" runat="server" DataSourceID="MyDataSource" ItemPlaceholderID="itemPlaceHolder" OnDataBound="ListView1_DataBound">
  2. <LayoutTemplate>
  3. <table border="1">
  4. <tr>
  5. <td>Name</td>
  6. <td>Age</td>
  7. <td runat="server" id="tdIsSuperCool">IsSuperCool</td>
  8. </tr>
  9. <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
  10. </table>
  11. </LayoutTemplate>
  12. <ItemTemplate>
  13. <tr>
  14. <td><%# Eval("Name") %></td>
  15. <td><%# Eval("Age") %></td>
  16. <td runat="server" id="myCol" visible='<%# (bool)Eval("IsSuperCool") %>'>true</td>
  17. </tr>
  18. </ItemTemplate>
  19. </asp:ListView>
  20. <asp:ObjectDataSource
  21. ID="MyDataSource"
  22. runat="server"
  23. DataObjectTypeName="BusinessLogicLayer.Thing"
  24. SelectMethod="SelectThings"
  25. TypeName="BusinessLogicLayer.MyObjectDataSource" />
  26.  
  27. /// <summary>
  28. /// Handles the DataBound event of the ListView1 control.
  29. /// </summary>
  30. /// <param name="sender">The source of the event.</param>
  31. /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  32. protected void ListView1_DataBound(object sender, EventArgs e)
  33. {
  34. ListView1.FindControl("tdIsSuperCool").Visible = false;
  35. }
  36.  
  37. style='display: <%#Eval("DisplayStyle") %>;'
  38.  
  39. <asp:ListView ID="ListView1" runat="server" DataSourceID="MyDataSource" ItemPlaceholderID="itemPlaceHolder">
  40. <LayoutTemplate>
  41. <table>
  42. <asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
  43. </table>
  44. </LayoutTemplate>
  45. <ItemTemplate>
  46. <tr>
  47. <td runat="server" id="myCol" visible='<%# (bool)Eval("IsSuperCool") %>'>
  48. <%# Eval("SuperCoolIcon") %>
  49. </td>
  50. <td>
  51. <%# Eval("Name") %>
  52. </td>
  53. <td>
  54. <%# Eval("Age") %>
  55. </td>
  56. </tr>
  57. </ItemTemplate>
  58. </asp:ListView>
  59.  
  60. foreach (ListViewItem item in ListView1.Items)
  61. {
  62. ((Panel)item.FindControl("myPanel")).Visible= False;
  63. }
Add Comment
Please, Sign In to add comment