Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
4.43/5 (3 votes)
See more:
public partial class WebFormAdmin_frmInternalMemo : System.Web.UI.Page { C}

In this class, I've a gridview with ID="gvListMemo"

I need to access this gridview in class named "public class Task { }" which is placed in the folder AppCode/Utility/Task.cs

how do I access it ????
Posted
Comments
Rahul VB 18-Jan-14 6:24am    
A very good question where developers get stuck many times.

You can try like this..

C#
public class Task
   {

       public void DoSomeAction(System.Web.UI.WebControls.GridView gridView)
       {
            // using the gridView object you can perform your desired action

       }

   }


in the Grid Page,


C#
Task objTask = new Task();
           objTask.DoSomeAction(gvListMemo);
 
Share this answer
 
Comments
Sriram Ramachandran 18-Jan-14 2:34am    
Thanks for your reply Karthik... I'll just try and say you the result
Karthik_Mahalingam 18-Jan-14 2:36am    
sure
Sriram Ramachandran 18-Jan-14 2:51am    
now i can access it .... but got stuck up with another problem. I'm using thread with timer. As you know, it executes with specific functions like Start(),Stop(), Execute() sequentially. My one of the functionality with timer works fine in Execute function. But need to call that DosomeAction function where i could not pass the gridview value. What am I supposed to do now ???

Execute ()
{
//how to call DoSomeAction function ????
}

public void Dosomeaction(System.Web.UI.WebControls.GridView gridview)
{


}
Karthik_Mahalingam 18-Jan-14 3:02am    
using this

Task objTask = new Task();
objTask.DoSomeAction(gvListMemo);

you can call the function..

it depends where you are calling this function. ( in button click , etc .. )
Sriram Ramachandran 18-Jan-14 3:02am    
private void Execute()
{
Reminder();
Abeyance();
Dosomeaction();
} I couldn't pass the gridview values in execute function or else this dosomeaction() doesn't run in my program...
Hello,

As Karthik sir said, you can pass that control to the method in another class.Like this :

public Class c1()
  {
   public void method(control c)
   {
       ////perform action on your control
   }
 
  }

  Main:
  
  c1 c = new c1();
  c.method(any_control); ///pass your control

 I can also do something like this : 


  public class c1()
   {
 
   control c;
      public c1(control c)
         {
         this.c = c;

         }


       public void method()
          { 
            ////use this.c to do anything you want, but you will have to type case it to the control you want. for example say to a textbox so
         
            TextBox t = (TextBox)this.c; /// try this out, sometimes throws runtime exception be vigilant while writing this sentence. You must understand the relation between base and derived classes.
            
          }

    }

  
  In the Main method :
  c1 c = new c1(any_control); 


Please note, the Control class is the base class of all controls(correct me if i am wrong).
So to make this algorithm generalized i can use the Control type to become the argument of a constructor or a method.

- I have used a constructor because it may happen that during class initialization you want to perform some operation with that control


Thanks,
-Rahul
 
Share this answer
 
Comments
Karthik_Mahalingam 18-Jan-14 8:28am    
5!
Rahul VB 18-Jan-14 10:11am    
thank you sir.
- Rahul
Karthik_Mahalingam 18-Jan-14 10:37am    
welcome Rahul :)
No Sir and all,karthik is fine.. :) ... i am a simple programmer..
Rahul VB 18-Jan-14 11:29am    
oh gosh you are so humble, ok Karthik, by the way i stayed in Banglore for 10 years, fantastic climate, its a long time now. Cherish those days in school KV banglore.
Karthik_Mahalingam 18-Jan-14 13:09pm    
Oh Good, my native is OOTY Tamil nadu, i am working in blr for last 2 years.
climate is good here.
wru now ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900