Thursday, October 18, 2012

Show hide Grid column using common function

1 To Hide column in perticular range :


public static void showhide(GridView gv,bool flag,int frmindex,int toindex,bool isfixcolhide,string footertext)
    {
        if (isfixcolhide)
        {
            gv.Columns[frmindex].Visible = flag;
            gv.Columns[frmindex + 1].FooterText = footertext;
        }
        else
        {
            for (int i = frmindex; i <= toindex; i++)
            {
                gv.Columns[i].Visible = flag;
            }
            gv.Columns[toindex + 1].FooterText = footertext;
        }
     
    }

Example:
            To hide Grid column from 1 to 11 as below with show footer text in next column :

                             showhide(gvrf, false, 1, 11, false, "total");

1 To Hide perticular columns using array index :

 

       public static  void showhide(GridView gv, bool flag, int[] index)
        {
            for (int i = 0; i <= index.Length; i++)
            {
                gv.Columns[index[0]].Visible = flag;
            }

        }

Example :  To hide column 1 and 3 as below :

                          int[] x = { 1, 3};
                            showhide(gvrf, false, x);

If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website