c# - Writing a generic with chaining instead of columns of grid -


i have columns in script following :

  <script>   $("#grid").kendogrid({               height: 400,               columns: [                  "productname",                   { field: "unitprice", format: "{0:c}", width: "150px" },                  { field: "unitsinstock", width: "150px" },                  { field: "discontinued", width: "100px" },                  { command: "destroy", title: "delete", width: "110px" }               ]   });   </script> 

i want write extension method using generic , chaining need in c# :

   <% page.grid<product>()      .columns.add(c=> {        c.add("productname").title("product name");        c.add("unitprice").title("unit price").width("150px");      }).render(); %> 

how can write c# method extension need use method in asp.net form.

i found out own answer:

kend._2013.extension.kendogrid<string>.name("kendogrid1")                                           .columns(c => new kend._2013.extension.column[]                                           {                                                                                                                                    c.add("productid").title("id").width(100),                                                 c.add("productname").title("name").width(150),                                                 c.add("unitprice").title("price").width(150),                                                 c.add("discontinued").title("amount").width(150),                                                 c.add("unitsinstock").title("units in").width(150),                                                                                      });          namespace kend._2013.extension {     public class column     {         private string fieldname;         private string title;         private int width;         private int height;          private readonly column previous;     private column(column previous)     {         this.previous = previous;     }      public column add(string name)     {         this.fieldname = name;         return new column(this);     }      public column title(string t)     {         this.title = t;         return new column(this);     }      public column width(int w)     {         this.width = w;         return new column(this);     }      public column height(int h)     {         this.height = h;         return new column(this);     } }  public class kendogriddatasource { }  public class kendogrid<t> {     private readonly t target;     private readonly kendogrid<t> previous;      private kendogrid(t target, kendogrid<t> previous)     {         this.target = target;         this.previous = previous;     }      public static kendogrid<t> name(t target)     {         return new kendogrid<t>(target, null);     }      private bool isfitinpage;     private int height;     private int width;     private column columns;     private bool pageable;     private bool sortable;     private bool filterable;     private bool editable;     private string uiculture;     private bool showcontextmenu;     private bool showfiltermenu;     private bool showgrouparea;     private bool showtoolbars;     private kendogriddatasource datasource;     private bool databatching;      private void fittopage(bool b)     {         this.isfitinpage = b;     }     public kendogrid<t> height(int h)     {         this.height = h;         return new kendogrid<t>(target, this);     }     public kendogrid<t> width(int w)     {         this.width = w;         return new kendogrid<t>(target, this);     }     public kendogrid<t> pageable(bool pageable)     {         this.pageable = pageable;         return new kendogrid<t>(target, this);     }     public kendogrid<t> sortable(bool sortable)     {         this.sortable = sortable;         return new kendogrid<t>(target, this);     }     public kendogrid<t> filterable(bool filterable)     {         this.filterable = filterable;         return new kendogrid<t>(target, this);     }     public kendogrid<t> editable(bool editable)     {         this.editable = editable;         return new kendogrid<t>(target, this);     }     public kendogrid<t> showcontextmenu(bool show)     {         this.showcontextmenu = show;         return new kendogrid<t>(target, this);     }     public kendogrid<t> showfiltermenu(bool show)     {         this.showfiltermenu = show;         return new kendogrid<t>(target, this);     }     public kendogrid<t> showgrouparea(bool show)     {         this.showgrouparea = show;         return new kendogrid<t>(target, this);     }     public kendogrid<t> showtoolbars(bool show)     {         this.showtoolbars = show;         return new kendogrid<t>(target, this);     }      public kendogrid<t> columns(expression<func<column, column>> col)     {                    var = col.compile();         column c = new column();         a(c);         return new kendogrid<t>(target, this);     }     public void render(){ // write html }   } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -