C
Chuck P
I have a gridview which I extended to allow adding rows. The extended
gridview hooks into the ObjectDataSource's Selected event. In the event I
add a new row to the List<T> returned by the ObjectDataSource select method.
Thus when the grid gets loaded it now has a empty row, which can be edited.
OnObjectDataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
Type typeList = e.ReturnValue.GetType(); //List<T> for a select statement
Type typeObj = e.ReturnValue.GetType().GetGenericArguments()[0]; //<T>
object ojb = Activator.CreateInstance(typeObj); //new T
// insert the new T into the list by using InvokeMember on the List<T>
object result = null;
object[] arguments = { 0, ojb };
result = typeList.InvokeMember("Insert", BindingFlags.InvokeMethod,
null, e.ReturnValue, arguments);
}
I went to modify the code to work with a LinqDataSource. Unfortunately,
their is no default constructor for the Objects created by LINQ, so the
CreateInstance method fails. Is their a way I can insert a new row with the
LinqDataSource?
thanks,
gridview hooks into the ObjectDataSource's Selected event. In the event I
add a new row to the List<T> returned by the ObjectDataSource select method.
Thus when the grid gets loaded it now has a empty row, which can be edited.
OnObjectDataSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
Type typeList = e.ReturnValue.GetType(); //List<T> for a select statement
Type typeObj = e.ReturnValue.GetType().GetGenericArguments()[0]; //<T>
object ojb = Activator.CreateInstance(typeObj); //new T
// insert the new T into the list by using InvokeMember on the List<T>
object result = null;
object[] arguments = { 0, ojb };
result = typeList.InvokeMember("Insert", BindingFlags.InvokeMethod,
null, e.ReturnValue, arguments);
}
I went to modify the code to work with a LinqDataSource. Unfortunately,
their is no default constructor for the Objects created by LINQ, so the
CreateInstance method fails. Is their a way I can insert a new row with the
LinqDataSource?
thanks,