I am working on a project(ASP.NET website) where i need to call method in webpage from a class.
///Default Page Method is
public partial class _Default :
I would do it the other way around. Add the method to the class (with a GridView as an argument):
public class BLMethods
{
public BLMethods(GridView gv)
{
List objPersonList = new List();
clsPerson objPerson = new clsPerson();
objPerson.personID = i;
objPerson.personName = "Person" + i;
objPersonList.Add(objPerson);
BindGridView(gv,objPersonList);
}
private void BindGridView(GridView gv, List objPersonList)
{
gv.DataSource = objPersonList.ToList();
gv.DataBind();
}
}
Default Page Method is
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BLMethods objBLMethods = new BLMethods(GridView1);
objBLMethods.BindingDataToControls();
}
}
Try giving getters and setters to your clsPerson class properties:
public class clsPerson
{
public int personID {get;set;}
public string personName {get;set;}
}