2009-07-11 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / System.Web.DynamicData / Test / WebPages / DynamicData / FieldTemplates / ForeignKey_Edit.ascx.cs
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Collections.Specialized;
6 using System.Linq;
7 using System.Web;
8 using System.Web.Security;
9 using System.Web.UI;
10 using System.Web.UI.WebControls;
11 using System.Web.UI.WebControls.WebParts;
12 using System.Web.UI.HtmlControls;
13 using System.Xml.Linq;
14 using System.Web.DynamicData;
15
16 public partial class ForeignKey_EditField : System.Web.DynamicData.FieldTemplateUserControl {
17     protected void Page_Load(object sender, EventArgs e) {
18         if (DropDownList1.Items.Count == 0) {
19             if (!Column.IsRequired) {
20                 DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
21             }
22
23             PopulateListControl(DropDownList1);
24         }
25     }
26
27     protected override void OnDataBinding(EventArgs e) {
28         base.OnDataBinding(e);
29
30         if (Mode == DataBoundControlMode.Edit) {
31             string foreignkey = ForeignKeyColumn.GetForeignKeyString(Row);
32             ListItem item = DropDownList1.Items.FindByValue(foreignkey);
33             if (item != null) {
34                 DropDownList1.SelectedValue = foreignkey;
35             }
36         }
37     }
38
39     protected override void ExtractValues(IOrderedDictionary dictionary) {
40         // If it's an empty string, change it to null
41         string val = DropDownList1.SelectedValue;
42         if (val == String.Empty)
43             val = null;
44
45         ExtractForeignKey(dictionary, val);
46     }
47
48     public override Control DataControl {
49         get {
50             return DropDownList1;
51         }
52     }
53 }