In the code for the ForeignKey_Edit user control, calls to DropDownList1.DataBind(); are not fetching the new
ActivityTypes. There must be some server-side caching going on somewhere but I'm not sure where to look.
This is just the auto-generated code (MSLinqToSQLGenerator), but the DataBind on line 22
is called each time the dropdownlist is expanded. It is here that values are missing.
Thanks
Mark
<%@ Control Language="C#" Inherits="System.Web.DynamicData.FieldTemplateUserControlBase" %>
<script runat="<span" class="st">"server">
4 // TODO: Clean this up. Some logic should be moved to base class.
5
6 protected void Page_Load(object sender, EventArgs e) {
7 DynamicMetaForeignKeyMember column = (DynamicMetaForeignKeyMember)MetaMember;
8
9 DynamicMetaTable parentTable = column.ParentMetaTable;
10
11 DropDownList1.DataSource = parentTable.Query;
12
13 DropDownList1.DataTextField = parentTable.DisplayMetaMember.Name;
14 // REVIEW: what if the PK has several columns?
15 DropDownList1.DataValueField = parentTable.IdentityMetaMembers[0].Name;
16
17 if (!column.IsRequired) {
18 DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
19 }
20
21 DropDownList1.AppendDataBoundItems = true;
22 DropDownList1.DataBind();
23
24 // Need to set DataSource back to null to make sure the framework doesn't bind a second time
25 DropDownList1.DataSource = null;
26 }
27
28 private string GetCurrentValue() {
29 DynamicMetaForeignKeyMember column = (DynamicMetaForeignKeyMember)MetaMember;
30 object value = DataBinder.GetPropertyValue(DataItem, column.KeyMetaMemberInThisTable.Name);
31
32 if (value == null)
33 return String.Empty;
34 return value.ToString();
35 }
36
37 protected override void OnDataBinding(EventArgs e) {
38 base.OnDataBinding(e);
39
40 if (TemplateMode == DynamicTemplateMode.EditItemTemplate) {
41 DropDownList1.SelectedValue = GetCurrentValue();
42 }
43 }
44
45 protected override void ExtractValues(IOrderedDictionary dictionary) {
46 // If it's an empty string, change it to null
47 string val = DropDownList1.SelectedValue;
48 if (val == String.Empty)
49 val = null;
50
51 DynamicMetaForeignKeyMember column = (DynamicMetaForeignKeyMember)MetaMember;
52 dictionary[column.KeyMetaMemberInThisTable.Name] = val;
53 }
54 </script>
"DropDownList1" runat="server" AppendDataBoundItems=true>
Mark, it looks like you are using a very old build, probably the one from December. Where did you install it from? I'm curious because maybe there is an old page somewhere that needs to be clarified to point to the new bits.
MarkHD
0 Points
9 Posts
How is a dropdownlist populated? Data is missing.
Jun 18, 2008 08:47 AM|LINK
Hi,
I have just built my first Dynamic Data Controls site and I like what I see.
I am trying to pinpoint a bug though. I have two tables Activity and ActivityType with a foreign key from Activity to ActivityType.
My DD website started started with an empty database.
I created some ActivityTypes and then an Activity which I linked to an ActivityType. Great!
But now whenever I add a new ActivityType I do not see it in the Activities page dropdownlist for ActivityTypes. Can anyone help please?
I tried profiling my database but in populating the Activity page no query was generated to fetch all of the ActivityTypes. Any ideas anyone?
Thanks
Mark
emady
Participant
1172 Points
198 Posts
Re: How is a dropdownlist populated? Data is missing.
Jun 18, 2008 09:06 AM|LINK
hi Mark,
I think your code to retrieve ActivityTypes is wrong. But I need to see your code to help you can you please send your code
Emad Yazdanpanah
From http://www.CSharpCourses.com
MarkHD
0 Points
9 Posts
Re: How is a dropdownlist populated? Data is missing.
Jun 18, 2008 09:28 AM|LINK
Hi Emad,
I am as you might have gathered a novice. [:)]
Which code do you want to see, the dbml? I've not used these forums before so not sure if I can upload files?
Thanks
Mark
MarkHD
0 Points
9 Posts
Re: How is a dropdownlist populated? Data is missing.
Jun 18, 2008 09:44 AM|LINK
P.S. I thought that the point was I don't have to write any code. Am I wrong?
MarkHD
0 Points
9 Posts
Re: How is a dropdownlist populated? Data is missing.
Jun 18, 2008 11:02 AM|LINK
In the code for the ForeignKey_Edit user control, calls to DropDownList1.DataBind(); are not fetching the new ActivityTypes. There must be some server-side caching going on somewhere but I'm not sure where to look.
emady
Participant
1172 Points
198 Posts
Re: How is a dropdownlist populated? Data is missing.
Jun 18, 2008 11:23 AM|LINK
can you please copy and paste into the post please
Emad Yazdanpanah
From http://www.CSharpCourses.com
MarkHD
0 Points
9 Posts
Re: How is a dropdownlist populated? Data is missing.
Jun 18, 2008 11:38 AM|LINK
This is just the auto-generated code (MSLinqToSQLGenerator), but the DataBind on line 22 is called each time the dropdownlist is expanded. It is here that values are missing.
Thanks
Mark
<%@ Control Language="C#" Inherits="System.Web.DynamicData.FieldTemplateUserControlBase" %>
<script runat="<span" class="st">"server"> 4 // TODO: Clean this up. Some logic should be moved to base class. 5 6 protected void Page_Load(object sender, EventArgs e) { 7 DynamicMetaForeignKeyMember column = (DynamicMetaForeignKeyMember)MetaMember; 8 9 DynamicMetaTable parentTable = column.ParentMetaTable; 10 11 DropDownList1.DataSource = parentTable.Query; 12 13 DropDownList1.DataTextField = parentTable.DisplayMetaMember.Name; 14 // REVIEW: what if the PK has several columns? 15 DropDownList1.DataValueField = parentTable.IdentityMetaMembers[0].Name; 16 17 if (!column.IsRequired) { 18 DropDownList1.Items.Add(new ListItem("[Not Set]", "")); 19 } 20 21 DropDownList1.AppendDataBoundItems = true; 22 DropDownList1.DataBind(); 23 24 // Need to set DataSource back to null to make sure the framework doesn't bind a second time 25 DropDownList1.DataSource = null; 26 } 27 28 private string GetCurrentValue() { 29 DynamicMetaForeignKeyMember column = (DynamicMetaForeignKeyMember)MetaMember; 30 object value = DataBinder.GetPropertyValue(DataItem, column.KeyMetaMemberInThisTable.Name); 31 32 if (value == null) 33 return String.Empty; 34 return value.ToString(); 35 } 36 37 protected override void OnDataBinding(EventArgs e) { 38 base.OnDataBinding(e); 39 40 if (TemplateMode == DynamicTemplateMode.EditItemTemplate) { 41 DropDownList1.SelectedValue = GetCurrentValue(); 42 } 43 } 44 45 protected override void ExtractValues(IOrderedDictionary dictionary) { 46 // If it's an empty string, change it to null 47 string val = DropDownList1.SelectedValue; 48 if (val == String.Empty) 49 val = null; 50 51 DynamicMetaForeignKeyMember column = (DynamicMetaForeignKeyMember)MetaMember; 52 dictionary[column.KeyMetaMemberInThisTable.Name] = val; 53 } 54 </script> "DropDownList1" runat="server" AppendDataBoundItems=true>MarkHD
0 Points
9 Posts
Re: How is a dropdownlist populated? Data is missing.
Jun 18, 2008 11:46 AM|LINK
OK, so it's the DD control code I pasted not the Linq code. Do you need to see any other code?
Thanks
Mark
davidebb
Contributor
7006 Points
1366 Posts
Microsoft
Re: How is a dropdownlist populated? Data is missing.
Jun 18, 2008 02:40 PM|LINK
Mark, it looks like you are using a very old build, probably the one from December. Where did you install it from? I'm curious because maybe there is an old page somewhere that needs to be clarified to point to the new bits.
In any case, please go to this CodePlex site to get the latest. Also, see this blog post.
thanks,
David
MarkHD
0 Points
9 Posts
Re: How is a dropdownlist populated? Data is missing.
Jun 18, 2008 03:37 PM|LINK
Thanks David, I will try this.
So do I build the DD extensions from the sources at the CodePlex site? If so, I'll hunt down the assemblies I don't have:
System.ComponentModel.DataAnnotations, System.Data.Services.Client, System.Web.DynamicData, System.Web.Routing.