views:

28

answers:

0

i try to learn refactoring my codes. i writed a base GridView class. This is:

 public static class GridViewUtil
    {

       public static GridView SendGridView(DataTable ds )
       {
           GridView gv = new GridView();
           gv.DataSource = ds;
           gv.DataBind();
           gv.HeaderStyle.BackColor = Color.Silver;
           gv.RowStyle.BackColor = Color.Silver;
           gv.RowStyle.BorderColor = Color.Black;
           return gv;
       }

    }

Also Default.aspx.cs :

 protected void Page_Load(object sender, EventArgs e)
        {
            LoadData ld = new LoadData();
            if (!IsPostBack)
            {
                PlaceHolder1.Controls.Add(GridViewUtil.SendGridView(ld.LoadSQL("conn", "sp_GetAllCategory")));
            }

        }

Another Type: MyGridView.cs base class:

 public static class GridViewUtil
    {

       public static GridView SendGridView(DataTable ds )
       {
           GridView gv = new GridView();
           gv.DataSource = ds;
           gv.HeaderStyle.BackColor = Color.Silver;
           gv.RowStyle.BackColor = Color.Silver;
           gv.RowStyle.BorderColor = Color.Black;
           return gv;
       }

    }

My Default.cs

protected void Page_Load(object sender, EventArgs e)
        {
            LoadData ld = new LoadData();
            GridView grv = new GridView();
            grv = GridViewUtil.SendGridView(ld.LoadSQL("conn", "sp_GetAllCategory"));
            if (!IsPostBack)
            {
                grv.DataBind();
                PlaceHolder1.Controls.Add(grv);
            }

        }

How can i use these codes: These codes runs good. But i want to refactoring them. Whch one is best or can you give advise about best solution or code style?