Can any one assits with; I am using VS2010 Entity Framwork 4 (ASP.Net 4)
On edit page i have 2 Associations; Old Category and New category both have Checkboxes (CheckboxList generated from ManyToMany Control). Before update i want to check new Categories checked list. I unable to see this.
I can able to see Current value and Original value of Main Table (using below code) but not the associated tables. I have use ADO.Net Entity Framework.
protectedvoid
DetailsDataSource_Updating(object
sender, EntityDataSourceChangingEventArgs
e) { var entry = e.Context.ObjectStateManager.GetObjectStateEntry(e.Entity); var
current = entry.CurrentValues; var Categoryname
= current.GetValue(current.GetOrdinal("CategoryName")).ToString();
}
I tried using FarmView to find FieldTemplateUserControl on "FormView_ItemUpdating" using below code but no luck. says "null" in tempField.
protected void
FormView1_ItemUpdating(object
sender, FormViewUpdateEventArgs
e) { FieldTemplateUserControl
tempField = (FieldTemplateUserControl)FormView1.FindFieldTemplate("CategoryNew1"); if
(tempField != null) { CheckBoxList
chklist = (CheckBoxList)tempField.DataControl; int
x = chklist.Items.Count; }
}
Thanks for looking on this.
I am using Dynamic Data Web application so code generated by microsoft. I can show you my Model design (.edmx) as below.
I got 3 tables as described below (To simplfy i use 3 tables)
LRM_Book
Bookid
Bookname
1
ABC
2
XYZ
3
OPQ
LRM_BookSecCategory
BookId
CatID
1
1
1
2
Category (Category table has self-join.)
CatID
CatNAme
ParentCatID
1
Cat_ABC
1
2
Cat_OPQ
1
3
Cat_XYZ
1
Above tables are simple, and easily understand the relationships, although I am explaining here.
I setup relationship In SQL Server 2008 using Database diagram. And simply call on to .edmx file and run project
It gives me LRM_Book Link on start page, I click on link jump on list.aspx page which has Gridview with my exiting records with relationship (Navigation), then Click "Edit" link on Gridview (one of record), take me on Edit.aspx page, Category fields provide
me with checkboxlist as it is manyToMany relation, this is exactly i am looking for. EF successfully save data for me as it has CRUD capability. However, I want to infer before EF saves data itself. like i want to see Oldvalue and CurrentValue.
So To infer i use below code.
protectedvoid
DetailsDataSource_Updating(object
sender, EntityDataSourceChangingEventArgs
e) {
var
entry = e.Context.ObjectStateManager.GetObjectStateEntry(e.Entity);
var
current = entry.CurrentValues; int
CBookID = (Int32)current.GetValue(current.GetOrdinal("BookId")); string CBookname =
current.GetValue(current.GetOrdinal("Bookname")).ToString();
var Original=
entry.OriginalValues; int
CBookID = (Int32)Original.GetValue(Original.GetOrdinal("BookId")); string CBookname =
Original.GetValue(Original.GetOrdinal("Bookname")).ToString();
//Above code works fine it gets main enity value in it but not child tables values
// now i want to see old category which was already selected and new (Current) category (this is ManyToMany relationship, which produce checkboxlist to select multiple categories for the one book)
}
I hope this make sense. If you want more information then i can send you screen shots; I unable to send screen shots on this editor.
pratiksolank...
Member
271 Points
76 Posts
Dynamic Data - While updating data on Edit.aspx page Get checkboxlist value which are checked
Aug 15, 2011 12:50 AM|LINK
Hi,
Can any one assits with; I am using VS2010 Entity Framwork 4 (ASP.Net 4)
On edit page i have 2 Associations; Old Category and New category both have Checkboxes (CheckboxList generated from ManyToMany Control). Before update i want to check new Categories checked list. I unable to see this.
I can able to see Current value and Original value of Main Table (using below code) but not the associated tables. I have use ADO.Net Entity Framework.
protected void DetailsDataSource_Updating(object sender, EntityDataSourceChangingEventArgs e)
{
var
entry = e.Context.ObjectStateManager.GetObjectStateEntry(e.Entity);
var current = entry.CurrentValues;
var Categoryname = current.GetValue(current.GetOrdinal("CategoryName")).ToString();
}
I tried using FarmView to find FieldTemplateUserControl on "FormView_ItemUpdating" using below code but no luck. says "null" in tempField.
protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
{
FieldTemplateUserControl tempField = (FieldTemplateUserControl)FormView1.FindFieldTemplate("CategoryNew1");
if (tempField != null)
{
CheckBoxList chklist = (CheckBoxList)tempField.DataControl;
int x = chklist.Items.Count;
}
}
Apreciate your help.
Pratik
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Dynamic Data - While updating data on Edit.aspx page Get checkboxlist value which are checked
Aug 17, 2011 02:28 AM|LINK
Hello pratiksolanki:)
Could you be kind enough to show us your aspx codes?
Thx again
pratiksolank...
Member
271 Points
76 Posts
Re: Dynamic Data - While updating data on Edit.aspx page Get checkboxlist value which are checked
Aug 17, 2011 03:22 AM|LINK
Hi Decker,
Thanks for looking on this.
I am using Dynamic Data Web application so code generated by microsoft. I can show you my Model design (.edmx) as below.
I got 3 tables as described below (To simplfy i use 3 tables)
LRM_Book
Bookid
Bookname
1
ABC
2
XYZ
3
OPQ
LRM_BookSecCategory
BookId
CatID
1
1
1
2
Category (Category table has self-join.)
CatID
CatNAme
ParentCatID
1
Cat_ABC
1
2
Cat_OPQ
1
3
Cat_XYZ
1
Above tables are simple, and easily understand the relationships, although I am explaining here.
(1) LRM_Book--> [BookID Primerykey ]-->LRM_BookSecCategory -->[BookID Foreignkey]
(2) Category [CatID PrimeryKey] --> Category --> [ParentCatID]
Selfjoin because I have multilevel subcategories
(3) Categoryà[CatID PrimeryKey]--> LRM_BookSecCategory -->[CatID Foreignkey]
I setup relationship In SQL Server 2008 using Database diagram. And simply call on to .edmx file and run project
It gives me LRM_Book Link on start page, I click on link jump on list.aspx page which has Gridview with my exiting records with relationship (Navigation), then Click "Edit" link on Gridview (one of record), take me on Edit.aspx page, Category fields provide me with checkboxlist as it is manyToMany relation, this is exactly i am looking for. EF successfully save data for me as it has CRUD capability. However, I want to infer before EF saves data itself. like i want to see Oldvalue and CurrentValue.
So To infer i use below code.
protected void DetailsDataSource_Updating(object sender, EntityDataSourceChangingEventArgs e)
{
var entry = e.Context.ObjectStateManager.GetObjectStateEntry(e.Entity);
var current = entry.CurrentValues;
int CBookID = (Int32)current.GetValue(current.GetOrdinal("BookId"));
string CBookname = current.GetValue(current.GetOrdinal("Bookname")).ToString();
var Original= entry.OriginalValues;
int CBookID = (Int32)Original.GetValue(Original.GetOrdinal("BookId"));
string CBookname = Original.GetValue(Original.GetOrdinal("Bookname")).ToString();
//Above code works fine it gets main enity value in it but not child tables values
// now i want to see old category which was already selected and new (Current) category (this is ManyToMany relationship, which produce checkboxlist to select multiple categories for the one book)
}
I hope this make sense. If you want more information then i can send you screen shots; I unable to send screen shots on this editor.
Regards
Pratik