LinqDataSource Adding Row

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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,

.



Relevant Pages

  • Re: GridView-FormView/Master-Detail with ObjectDataSource
    ... discusses how to use Master and Detail (FormView) model ... The problem I am having is that Formview's EditItemTemplate does not ... Selected event handler of the Formview's objectdatasource. ...
    (microsoft.public.dotnet.framework.aspnet)
  • How to re-select row in a gridview _after_ sorting?
    ... I have a gridview with ObjectDataSource attached and page/sort enabled. ... index and selected index (i.e. if the selected data happens to be on the ... The sort occurs after the Selected event so I have no way of determining on ... _after_ the ObjectDataSource sort operation is performed? ...
    (microsoft.public.dotnet.framework.aspnet)
  • GridView-FormView/Master-Detail with ObjectDataSource
    ... In the selectedIndex changed event of gridview, ... Selected event handler of the Formview's objectdatasource. ... The the select paramater of objectdatasource to which the FormView is ...
    (microsoft.public.dotnet.framework.aspnet)
  • ObjectDataSource completely in code behind
    ... I'm dynamically creating PDFs and trying to create an objectdatasource ... selected event. ... ObjectDataSource Appendix1 = new ObjectDataSource; ...
    (microsoft.public.dotnet.languages.csharp)