Modify Child Object During Gridview OnUpdate Using ObjectDataSource?

Sep 2, 2010

Backgroud: I'm using NHibernate for my model layer, and I have a HTTP module taking care of instantiating the session at the beginning of each request and cleaning it up at the end of each request (i.e. Session Per Request). In this case, I have two object types:

ParentItem - an object with a bunch of properties and a collection of ChildItems. ChildItem - an object with properties including a DateTime (EffectiveDate) and an unenforced FK pointing to a completely different database. The ChildItem class contains a reference back to the parent as well (many-to-one) While the ParentItem has multiple ChildItems in its collection, I'm only generally interested in the latest ChildItem in the collection.

Desire: Want a databound control (GridView or ListView, I don't care which) that allows me to Add/Edit/Delete ParentItems from my datasource. I also want to have the ability to set a new "latest" ChildItem as part of the edit/update.

Issue: I can't seem to access the underlying DataItem from the GridView/ListView in the OnItemUpdating handler (which isn't unexpected, since the data is now in the viewstate). What I thought I could do would be to load a ParentItem from my session using the ID from the databound control, create a new ChildItem, add it to the ParentItem, and then save the ParentItem. Since NHibernate caches the data, the load should give me a copy from cache (no roundtrip to the DB) and I'd either be doing this before the ParentItem was saved back (thus no changes committed to ParentItem, just to ChildItem) or after (thus the cached version is still the same, and my new object will match the updated version). What I get when I do this (for ParentItemID=1):

a different object with the same identifier value was already associated with the session: 1, of entity:

NameSpace.ParentItem

on the line:

Session.SaveOrUpdate(parentItemInstance);

View 1 Replies


Similar Messages:

C# - How To Access ObjectDataSource Object After Bind To GridView

Feb 4, 2010

I have a GridView, I bind it to ObjectDataSource. ObjectDataSource takes data from a database's table. Each row in table has unique ID.

I have a button in each row of GridView that should remove this row from database. My ObjectDataSource returns Object, this returned object contains ID (and some other information, like name, user etc.) however I do not show this ID on my grid.

how can I get these ID after user chooses to delete row, I need to know what I should remove.

View 2 Replies

Forms Data Controls :: ObjectDataSource For GridView Is Not Creating Original_{0} And New Values Object?

Mar 9, 2010

I am trying to update record in gridview using ObjectDataSource (with conflict detection)The following is the ObjectDataSource

[Code]....

Update Method is as follows

[Code]....

In ObjectDataSourceProducts_Updating(..) event , I am checking objects which are being sent to UpdateProduct(..) method. I found that both the objects " original_ProductDB and productDB " have the same the values. When I click "Update" in GridView after entering new value, ObjectDataSource is not picking new value

[Code]....

GridView is as follows.

[Code]....

ProductBO is as follows

[Code]....

View 3 Replies

Binding Data To A GridView From A Object With Child Objects Containing Relevant Fields

Jul 16, 2010

I have a List of complex objects containing other objects within that I give as the data source to a gridview.(currently I'm using BoundFields for the columns). I need to bind data to the columns from the objects within at run time. How can this be done?

View 1 Replies

C# - Modify XML File With A Dataset And Child Relations?

Mar 14, 2011

I want to modify an existing XML-File.

I used a DataSet to load the XML File with the ReadXml method.

I then displayed the relevant entries via the GetChildRows method.

I want to change/add/delete those ChildRows:

How can I accomplish this?

Below is the xml before edit

[code]....

View 1 Replies

Receiving Object Reference Not Set To An Instance Of An Object When Binding Child DataGrid?

Mar 12, 2010

I am receiving Object reference not set to an instance of an Object when binding Child dataGrid in the ItemCommandEvent of Parent dataGrid.

[code].....

View 1 Replies

DataSource Controls :: Get Child Properties Using Parent Object Error / Cannot Access A Disposed Object

Feb 17, 2010

On DBML I have two entities as Parent, Child. I am trying to assign Child class properites in a Parent.

[code]....

I am getting the following Error:

Cannot access a disposed object.

Object name: 'DataContext accessed after Dispose.'.

View 2 Replies

Modify An Object From Cache And It Changes The Cached Value

May 8, 2010

I'm having an issue when using the Asp.Net Cache functionality. I add an object to the Cache then at another time I get that object from the Cache, modify one of it's properties then save the changes to the database.

But, the next time I get the object from Cache it contains the changed values. So, when I modify the object it modifies the version which is contained in cache even though I haven't updated it in the Cache specifically. Does anyone know how I can get an object from the Cache which doesn't reference the cached version?i.e.

Step 1:
Item item = new Item();
item.Title = "Test";
Cache.Insert("Test", item, null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration);

Step 2:
Item item = (Item)Cache.Get("test");
item.Title = "Test 1";

Step 3:
Item item = (Item)Cache.Get("test");
if(item.Title == "Test 1"){
Response.Write("Object has been changed in the Cache.");
}

I realise that with the above example it would make sense that any changes to the item get reflected in cache but my situation is a bit more complicated and I definitely don't want this to happen.

View 2 Replies

C# - ObjectDataSource Return Object From Cache?

Jan 13, 2011

Is there any way to return object from Session when Select is called on ObjectDataSource? Specifically, I have Products object and saved in Session. Now on another page I have ObjectDataSource which will call same bussiness object method to get Products object. Here I want to hook up any event like Selecting and I would like to return Products object from Session to Select method of ObjectDataSource.

View 1 Replies

C# - Linq To Sql Dynamic Data Modify Object Before Insert And Update?

Jun 18, 2010

I'm using Dynamic Data and LINQ to SQL for some admin pages on a .NET 3.5 web app. All my admin tables have a CreatedBy, CreatedDate, UpdatedBy, and UpdatedDate.I'm looking for a way to inject the setting of these properties before the objects are inserted and updated.

I've seen an object_inserting hook if you have a linq to sql datasource in the web form, but I'm using dynamic data...is there an easy way to generically set that? And I've also looked at modifying each of the partial classes for my admin objects, but the closest hook I see is to implement the OnValidate method with the Insert action.

View 1 Replies

Accessing An Object That Implements SelectMethod For ObjectDataSource?

Nov 8, 2010

Is it possible to access an object that is used by ObjectDataSource to retrieve records? For example,

<asp:ObjectDataSource ID="MyDS" runat="server"
SelectMethod="getUsers"
TypeName="DataSources.UserDS"
SelectCountMethod = "getUserNum"/>... </asp:ObjectDataSource>

UserDS class has getUsers that returns DataTable and getUserNum that returns int, this part works as it's supposed. But I wonder if can access the instance of UserDS somehow (not underlying DataTable)?

View 1 Replies

C# - How To Catch Exception Occurred In DAL Of ObjectDataSource Object

Sep 1, 2010

I have ObjectDataSource and GridView on one of the pages of my asp.net web project.

To initialize ObjectDataSource i use Init event:

protected void ObjectDataSource1_Init(object sender, EventArgs e)
{
ObjectDataSource1.EnablePaging = true;
ObjectDataSource1.TypeName = "CustomerDataSource";
ObjectDataSource1.DataObjectTypeName = "Customer";
ObjectDataSource1.SelectMethod = "GetCustomers";
ObjectDataSource1.UpdateMethod = "Update";
ObjectDataSource1.SelectCountMethod = "GetCustomersCount";
ObjectDataSource1.MaximumRowsParameterName = "maximumRows";
ObjectDataSource1.StartRowIndexParameterName = "startRowIndex";
}

Somewhere in DAL:

public static List<Customer> GetCustomers(int maximumRows, int startRowIndex)
{
try {
... some select to database here...
}
catch (Exception ex)
{
Utils.LogError(ex);
throw ex;
}
}

Now let's imagine that GetCustomers for some reason throws an exception. How could i catch this exception and handle it? I know i can use Application_Error, but i would like to catch this exception somehow on my page and show some friendly message to the user.

View 1 Replies

How To Get The Inserted Id Or Object After An Insert With The FormView/ObjectDataSource Controls

Feb 22, 2010

I have a series of classes that loosely fit the following pattern:

public class CustomerInfo {
public int Id {get; set;}
public string Name {get; set;}
public class CustomerTable {
public bool Insert(CustomerInfo info) { /*...*/ }
[code]...

View 1 Replies

DataSource Controls :: Pass Object As SessionParameter In ObjectDataSource?

Dec 28, 2010

Is it possible to pass a domain object as session parameter in an ObjectDataSource. I'm doing this:

<asp:ObjectDataSource ID="ParticipantsDataSource" runat="server" OnInit="SqlDataSource_Load"
SelectMethod="LoadParticipants" TypeName="SB.Web.units.Players">
<SelectParameters>
<asp:SessionParameter Name="user" SessionField="User" Type="SB.BusinessLogic.DomainEntity.User" />
</SelectParameters>
</asp:ObjectDataSource>

But I get the error message that I can't create an object of the type System.TypeCode from the string containing SB.BusinessLogic.DomainEntity.User for the property Type.

View 1 Replies

SQL Server :: Cannot Add A New Column / Unable To Modify Table.Invalid Object Name 'MSED_Logs.DatabaseLog'

Dec 8, 2010

I cannot add a new column in existing table.

I have a two tables ['ev_event_how' & 'ev_events_event_how'] has relationship between these table.

Ex:

Table: 'ev_event_how'

UID - Event[PK]

Ex:

Table: 'ev_events_event_how'

UID - Event[FK] - Desc

I want to add a one more column[IsDelete] in both table. But Sql server is not allowing to add the new column, Showing various errors like

1.cannot add a new column-Unable to modify table.Invalid object name 'MSED_Logs.DatabaseLog'

2.TITLE: Microsoft SQL Server Management Studio

User canceled out of save dialog (MS Visual Database Tools)

How can I make it add a new column in existing table?

View 4 Replies

Data Controls :: Collapse Nested Child GridView When Another Nested Child GridView Is Expanded?

Jan 24, 2016

I have designed a collapsible nested gridview project using this article as a reference Collapsible Nested GridView with Paging using ASP.Net. I am trying to modify the code to collapse a gridview when another gridview is expanded so that only one nested gridview will be open at a time.

View 1 Replies

DataSource Controls :: Objectdatasource Return Inserted Object Like LinqDatasource Do?

Mar 5, 2010

I would like the ObjectDatasource insert and update data methods to return the inserted or updated object like LinqDataSource do.

View 2 Replies

DataSource Controls :: How To Pass An Object To The Selectmethod Of The Objectdatasource Control

Mar 31, 2011

how to pass an object to the selectmethod of the objectdatasource control?

View 2 Replies

DataSource Controls :: Passing Object To ObjectDataSource.SelectParameters Collection

Mar 30, 2010

I'm trying to use an ObjectDataSource's SelectMethod() to retrieve a result set from a sql server database to populate a data table with various stored procs that have any given number of parameters. My approach is to pass an object which contains the stored proc name and information about its parameters into the SelectMethod(). My issue is that I don't know how to actually set the default value. Here is the code I have so far:

ObjectDataSource1.DataObjectTypeName = "WebApplication1.Children";
ObjectDataSource1.TypeName = "WebApplication1.Children";
ObjectDataSource1.SelectMethod = "Select";

Parameter odsParameter = new Parameter() { Name = "storedProc", Type = TypeCode.Object };

// How do you set the default value to reference an object?

ObjectDataSource1.SelectParameters.Add(odsParameter);

namespace WebApplication1
{
public class Children
{
public DataTable Select(object storedProc)
{
// do stuff here and get db values.
}
}
}

The default value of a Parameter object is a string type. Does anyone know how to set the default value with an object or how I can pass an object into the SelectMethod?

View 2 Replies

Visual Studio :: DataSet Not Recognized As Buesiness Object By ObjectDataSource?

Nov 15, 2010

I have an ObjectDataSource in Visual Studio 2008. I have a DataSet defined with a TableAdapter. However, when I go to select the Table Adapter to use in the ObjectDataSource, nothing shows up. I double checked that the DataSet is in fact in the App_Code folder. I do not know what else to try. The following code is the ASP code for that ObjectDataSource:

asp:ObjectDataSource
ID="ObjectDataSource1"
runat="server"
DeleteMethod="Delete"
InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="NewDataSetTableAdapters.PlansTableAdapter"

[Code].....

View 1 Replies

C# - Enable Filtering On An Objectdatasource With Filterexpression When Bound To A List <object>?

Nov 29, 2010

how to use FilterExpression with an object datasource when it is bound using a selectmethod that returns a list of entity objects?

I get the following error when I attempt it.

The data source 'testODS' only supports filtering when the SelectMethod returns a DataSet or a DataTable

View 2 Replies

ObjectDataSource Databinding: Getting Object Properties By Select Method Call - How To Access Value

Feb 22, 2010

I am using an ObjectDataSource control to call a MapInfo object. This object has two properties:

public IList Visits
public int TotalAvailable

The select method returns an IList but the TotalAvailable property is also populated. I have set the TypeName in the ObjectDataSource to the MapInfo object but because the Select method only returns the IList I don't have access to the TotalAvailable.

[code]....

Is there any way to access this value. I know it is being populated in the MapInfo object but all that gets returned from the Select method is the IList

View 2 Replies

DataSource Controls :: Make ObjectDataSource Typename Of A Singleton Business Object?

Mar 14, 2010

How do I make ObjectDataSource work with singleton Business object? My singleton business object is defined in Global:

[Code]....

I get an error:The type specified in the TypeName property of ObjectDataSource 'objThreads' could not be found.

View 2 Replies

Web Forms :: Master Page Control In Child Page Error "Object Reference Not Set To An Instance Of An Object"

Aug 31, 2010

i have create dynamic menu control , i have master page and login page , once the user login , i want to show the dynamic menu in my master page. below i try to call masterpage control in my child page ,but i throughs the error

Object reference not set to an instance of an object.
my master page code
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string MyProperty
{
set
{
// lblUser.Text = value;
lblUser.Text = value; // here i got the error
}
}
}

My child page code

protected void btnwork_Click(object sender, EventArgs e)
{
((MasterPage)this.Master).MyProperty = "Text changed from Sub Page";
}

View 5 Replies

Ms Entity Framework Delete Child Object

Mar 10, 2010

i have 2 tables without any cascade deletind. i wont to delete parent object with all child objects. i do like this

//get parent object
return _dataContext.Menu.Include("ChildMenu").Include("ParentMenu").Include("Pictures").FirstOrDefault(m => m.MenuId == id);
//then i loop all child objects
var picList = (List<Picture>)menu.Pictures.ToList();
//foreach (var item in menu.Pictures)
for (int i = 0; i < picList.Count; i++)
{
if (File.Exists(HttpContext.Current.Server.MapPath(picList[i].ImgPath)))
{
File.Delete(HttpContext.Current.Server.MapPath(picList[i].ImgPath));
}
if (File.Exists(HttpContext.Current.Server.MapPath(picList[i].ThumbPath)))
{
File.Delete(HttpContext.Current.Server.MapPath(picList[i].ThumbPath));
}
//**what must i do here?**
//menu.Pictures.Remove(picList[i]);
// DataManager dm = new DataManager();
// dm.Picture.Delete(picList[i].Id);
//menu.Pictures.de
//_dataContext.SaveChanges();
//picList[i] = null;
}
//delete parent object
_dataContext.DeleteObject(_dataContext.Menu.Include("ChildMenu").Include("ParentMenu").Include("Pictures").FirstOrDefault(m => m.MenuId == id););
_dataContext.SaveChanges();

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved