none
How to hide a column of a Listview? RRS feed

  • Question

  • Dear guys,

    How to hide a column of a Listview by a running code? But i will need be able to read the data, because i have a Current user filter webpart connected.

    Thanks
    Chong
    • Edited by Chong Man Thursday, June 18, 2009 9:20 PM
    Thursday, June 18, 2009 9:19 PM

Answers

  • Thanks guys,

    Finally i changed the listviewwebpart to DataFormWebPart, so i can code with better. Example below:

    <th class="ms-vh" nowrap="nowrap" style="display:none;">AgencyCode</th>

    On the DataFormWebPart, i had to set up a parameter by this AgencyCode field and filtered by it.
    Current user webpart, i just need to connected to DataFormWebPart to send the parameter to.

    I had fun with it! Thanks again!
    Chong
    • Marked as answer by Chong Man Friday, June 19, 2009 3:36 PM
    Friday, June 19, 2009 3:36 PM

All replies

  • You can create ListView webpart programmaticallly,



    Hope this will help you.
    Thursday, June 18, 2009 9:47 PM
  • Thanks Milan,

    But what i want is how to hide a field of a listviewwebpart by code like javascript sth, and i have a Current user filter webpart that need to filter by this field. Which means I need get data from that field and need it invisible.

    i don't know below will work or break it.

    list.Fields["Room No."].ShowInDisplayForm = false; 
    list.Fields["Room No."].Update();

    Chong
    • Edited by Chong Man Friday, June 19, 2009 3:42 AM
    Friday, June 19, 2009 3:39 AM
  • Hi,

    SPView

    view = this.list.Views[0]; //Get the correct view with either name or index
    SPViewFieldCollection coll = view.ViewFields; //Get the field collection of the view

    coll.Delete(

     

    SPFieldObject);  //Then delete the Field by passing the SPField object, then update if required.


    Hope this helps.....

    Regards,
    Jagan.

    Friday, June 19, 2009 6:21 AM
  • Thanks guys,

    Finally i changed the listviewwebpart to DataFormWebPart, so i can code with better. Example below:

    <th class="ms-vh" nowrap="nowrap" style="display:none;">AgencyCode</th>

    On the DataFormWebPart, i had to set up a parameter by this AgencyCode field and filtered by it.
    Current user webpart, i just need to connected to DataFormWebPart to send the parameter to.

    I had fun with it! Thanks again!
    Chong
    • Marked as answer by Chong Man Friday, June 19, 2009 3:36 PM
    Friday, June 19, 2009 3:36 PM
  • Thanks Jagan,

    If i delete this column, then i can't filter by it. By the funny design, I have to keep it and also make it hide.

    Chong
    Friday, June 19, 2009 3:37 PM