Showing posts with label gridview. Show all posts
Showing posts with label gridview. Show all posts

Sunday, October 6, 2013

RegisterForEventValidation can only be called during Render();






 
 
When we export gridview data to excel,word,notepad and csv using asp.net  we found this type of error :
 
 
This error occurs whenever we are trying to render control to response. To solve this problem I have added EnableEventValidation="false" to @Page directive of aspx page that should be just like this 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExportGridviewtoExcel.aspx.cs" Inherits="ExportGridviewtoExcel" EnableEventValidation="false"%>
By Setting EnableEventValidation="false" property to @Page directive of aspx page the problem has solved automatically.
 
 
Second problem in export to excel is  :
 
  "Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
 
 
Add this code in server side :
 
 
public override void VerifyRenderingInServerForm(Control control)
    {
        //It solves the error "Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server."
    } 

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

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