LinqDataSource Adding Row
- From: Chuck P <Chuck@xxxxxxxxxxxxxxxx>
- Date: Tue, 6 May 2008 14:08:03 -0700
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,
.
- Follow-Ups:
- RE: LinqDataSource Adding Row
- From: "Wen Yuan Wang [MSFT]"
- RE: LinqDataSource Adding Row
- Prev by Date: Connect without async but get timeout error when async=true
- Next by Date: Scalar vs Reader Exec Method
- Previous by thread: Connect without async but get timeout error when async=true
- Next by thread: RE: LinqDataSource Adding Row
- Index(es):
Relevant Pages
|