Call ASP.NET page method from class file method

前端 未结 4 1810
不思量自难忘°
不思量自难忘° 2021-01-29 05:38

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 :         


        
4条回答
  •  春和景丽
    2021-01-29 06:23

    You should be returning only data from business rule class and bind grid view in the code behind class.

    you can make method in the class which will return the List and on page load bind it with your girdview:

    public class BLMethods 
        {
            public BLMethods()
            {
    
            }
    
            public List GetPersons()
            {
              List objPersonList = new List();
              clsPerson objPerson = new clsPerson();
              objPerson.personID = i;
              objPerson.personName = "Person" + i;
              objPersonList.Add(objPerson);
    
              return objPersonList ;
            }
        }
    

    and in code behind of page:

    protected void Page_Load(object sender, EventArgs e)
        {
           BindGridView();
        }
    
        public void BindGridView()
        {             
          BLMethods objBLMethods = new BLMethods();
          GridView1.DataSource = objBLMethods.GetPersons();
          GridView1.DataBind();
        }
    

提交回复
热议问题