Which is the recommended way to fill all controls on a Web Form when user selects a record?

后端 未结 3 1838
既然无缘
既然无缘 2021-01-17 17:39

I have a GridView control which shows a list of all employees. When user selects any employee from this list, the record is shown on a Web Form with all input controls pre-f

3条回答
  •  走了就别回头了
    2021-01-17 18:05

    The way I would perform this task since you want to create a data access layer is to create a class which has all the properties

    Class:

    public class tw_main
    {
         public string SchemeCode {get;set;}
    }
    

    DAL:

    public class dal
    {
      public tw_main getSelectedValue(pass the parameters required by the method)
      {
        //your connection and query code
        var twmain = new tw_main();
        twmain.SchemaCode =  ds.Tables[0].Rows[0]["schm_code"].ToString(); 
    
        return twmain;
      }
    }
    

    Web Page:

    //depending upon where you add this a reference may need to be imported (using) to the namespace
      var dalObj = new dal();
      var tw = dalObj.getSelectedValue();
    lblSchemeCode.Text = tw.SchemaCode;
    

提交回复
热议问题