gridview hidden columns and paging

Last post 07-07-2009 3:53 PM by alessandro. 1 replies.

Sort Posts:

  • gridview hidden columns and paging

    07-07-2009, 2:53 PM
    • Member
      11 point Member
    • issam1975
    • Member since 04-21-2009, 1:34 PM
    • Posts 67

    hi

    i have a gridview with some hidden fields wih this code

         GridView2.HeaderRow.Cells[3].Visible = false;
            GridView2.HeaderRow.Cells[4].Visible = false;
            foreach (GridViewRow gvr in GridView2.Rows)
            {
                gvr.Cells[3].Visible = false;
                gvr.Cells[4].Visible = false;
            }

         GridView2.HeaderRow.Cells[3].Visible = false;

            GridView2.HeaderRow.Cells[4].Visible = false;

            foreach (GridViewRow gvr in GridView2.Rows)

            {

                gvr.Cells[3].Visible = false;

                gvr.Cells[4].Visible = false;

            }


    i use this code to get the hiddens fields data for processing 

    (the user don't need to view thses fields)

    it works but if i click on another page in the pager the hidden fields become visible


    thanks for any assistance

  • Re: gridview hidden columns and paging

    07-07-2009, 3:53 PM
    Answer
    • Contributor
      6,788 point Contributor
    • alessandro
    • Member since 06-25-2002, 2:05 PM
    • Italy
    • Posts 1,103

     why don't you do this declaratively on the boundfield itself. Then it should just work without you having to maintain the code to ensure that it runs on postback.

    You are aware that when you page, you are posting back to the server and your page goes through it's normal life cycle, init, page_load,postbacks, prerender etc

    so ensure that when you are clicking the pager buttons and posting back, the lines you pasted are re-executed. During a paging operation, the data control is rebound and it loses state (unfortunately for you).

    Alessandro Zifiglio
    www.jiffycms.net - opensource HTML Editor for ASP.NET
    http://weblogs.asp.net/alessandro


    In the land of the blind, the man with one eye is king!:x
Page 1 of 1 (2 items)