c# - trying to combine two similar user controls using generics -
c# - trying to combine two similar user controls using generics -
i saw next here in stackoverflow
void somemethod<t>(list<t> somelist) { if (typeof(t) == typeof(c1)) { // etc } } i trying incorporate somehow in following. i'm trying combine 2 similar user controls using generics
public partial class uccustomers : system.web.ui.usercontrol { list<customer> _list; public void setdatasource(list<customer> customers){ _list = customers } } public partial class ucproducts : system.web.ui.usercontrol { list<products> _list; public void setdatasource(list<product> products){ _list = products } } problem is, i'd set fellow member _list variable won't allow me unless like:
ienumerable _list; but can't utilize lambda's type of variable. goal have gridview user command has basic crud functionality.
i'm thinking setdatasource take generic list , work fellow member variable.
i think generic class constraint need. if products , customer not derived usercontrol, can modify where clause.
public class uc<t> : usercontrol t : usercontrol { private list<t> _list; public void setdatasource(list<t> list) { _list = list; } } c# asp.net user-controls
Comments
Post a Comment