2016-12-14 5 views
0

xmlからビルドされた動的フォームがあります。私はフォームを生成することができますが、私はそれから新しい値を得ることはできません。私は生成された古い値だけを取得します。古いものとは異なる値を更新したいと思います。問題は、page_initの新しい値を古いもので上書きすることだと思いますか?FormView IBindableTemplateはFormViewUpdateEventArgsから新しい値を取得できません。

これは私がachiveたいものをより良く理解するために私のUIへのDropboxのリンクです:私は保護された無効Page_Init(オブジェクト送信者、EventArgsの電子) {

Page_init

でこれを呼び出す https://www.dropbox.com/s/nacs9ohgjxefft9/FormView.png?dl=0#

public sealed class FormViewEditTemplate : IBindableTemplate 
{ 
    public FormViewEditTemplate(ListItemType type, mmXMLdoc.mmXMLdoc editXmlForm) 
    { 
     templateType = type; 
     _editXmlForm = editXmlForm; 

    } 
    //This method provides a way to insert an instance of text and controls into the specified container. 
    void ITemplate.InstantiateIn(Control container) 
    { 
     tabela = new Table(); 
     tabs = new TabContainer(); 
     tapPanel = new TabPanel(); 
     row = new TableRow(); 
     switch (templateType) 
     { 

      case ListItemType.EditItem: 

       List<XmlElement> Controls = _editXmlForm.getNodCollection("//Tabs"); 
       if (Controls.Count > 0) 
       { 
        //pridobimo tabe za formo 
        foreach (XmlElement ctrlItem in Controls) 
        { 
         var ControlsItems = _editXmlForm.getNodCollection("./Controls", "Control", -1, ctrlItem); 
         tabela = new Table(); 
         tapPanel = new TabPanel(); 
         tapPanel.ID = Guid.NewGuid().ToString(); 
         tapPanel.HeaderText = ctrlItem.GetAttribute("name").ToString(); 
         //pridobimo podatke za formo 
         //var controls1 = ctrlItem.SelectNodes("//Controls"); 
         foreach (XmlElement ctrl in ControlsItems) 
         { 
          string name = _editXmlForm.gStr("./@name", -1, ctrl) + Guid.NewGuid().ToString(); 
          string label = _editXmlForm.gStr("./@label", -1, ctrl); 
          string width = _editXmlForm.gStr("./@width", -1, ctrl); 
          string type = _editXmlForm.gStr("./@type", -1, ctrl); 
          string value = String.Empty; 
          string helpnote = _editXmlForm.gStr("./HelpNote", -1, ctrl); 
          string boundfield = _editXmlForm.gStr("./BoundField", -1, ctrl); 
          row = new TableRow(); 
          TableCell cell = new TableCell(); 
          switch (type) 
          { 
           case "TextBox": 

            //The TemplateField allows for a mix of HTML markup, Web controls, and data-binding syntax. 
            Label lbl_item = new Label(); 
            lbl_item.Font.Bold = true; 
            lbl_item.Text = label + ": "; 
            cell = new TableCell(); 
            cell.Controls.Add(lbl_item); 
            row.Controls.Add(cell); 


            TextBox txt_item = new TextBox(); 
            txt_item.ID = boundfield; 
            txt_item.Text = boundfield; 
            txt_item.DataBinding += new EventHandler(txt_DataBind); 
            cell = new TableCell(); 
            cell.Controls.Add(txt_item); 
            row.Controls.Add(cell); 

            break; 
           case "CheckBox": 
            lbl_item = new Label(); 
            lbl_item.Font.Bold = true; 
            lbl_item.Text = label + "<br/>"; 
            //The BoundField displays the value of specified DataSource field as text. 
            BoundField bfield = new BoundField(); 
            bfield.HeaderText = label; 
            bfield.DataField = boundfield; 
            break; 

           default: 
            break; 
          } 

          tabela.Controls.Add(row); 

         } 
         tapPanel.Controls.Add(tabela); 
         tabs.Controls.Add(tapPanel); 
        } 
       } 
       break; 
      case ListItemType.Footer: 

       Button saveButton = new Button(); 
       saveButton.Command += new CommandEventHandler(SaveButton_Command); 
       saveButton.CommandName = "Update"; 
       saveButton.Text = "Save"; 
       saveButton.ID = "EditButton"; 
       container.Controls.Add(saveButton); 
       break; 
     } 

     container.Controls.Add(tabs); 
    } 

IOrderedDictionary IBindableTemplate.ExtractValues(Control container) 
    { 
     OrderedDictionary dict = new OrderedDictionary(); 
     List<XmlElement> Controls = _editXmlForm.getNodCollection("//Tabs"); 
     if (Controls.Count > 0) 
     { 
      //pridobimo tabe za formo 
      foreach (XmlElement ctrlItem in Controls) 
      { 
       var ControlsItems = _editXmlForm.getNodCollection("./Controls", "Control", -1, ctrlItem); 

       foreach (XmlElement ctrl in ControlsItems) 
       { 
        string type = _editXmlForm.gStr("./@type", -1, ctrl); 
        string boundfield = _editXmlForm.gStr("./BoundField", -1, ctrl); 

        switch (type) 
        { 
         case "TextBox": 
          TextBox tb = (TextBox)FindControlRecursive(container, boundfield); 
          if (tb != null) 
           dict[boundfield] = tb.Text; 
          break; 
         case "Label": 
          Label lb = (Label)FindControlRecursive(container, boundfield); 
          if (lb != null) 
           dict[boundfield] = lb.Text; 
          break; 
         case "CheckBox": 
          CheckBox cb = (CheckBox)FindControlRecursive(container, boundfield); 
          if (cb != null) 
           dict[boundfield] = cb.Checked; 
          break; 
         case "DropDown": 
          DropDownList ddl = (DropDownList)FindControlRecursive(container, boundfield); 
          if (ddl != null) 
           dict[boundfield] = ddl.SelectedValue; 
          break; 
         default: 
          break; 
        } 
       } 
      } 

     } 
     return dict; 
    } 

    private Control FindControlRecursive(Control ctlRoot, string sControlId) 
    { 
     // if this control is the one we are looking for, break from the recursion 
     // and return the control. 
     if (ctlRoot.ID == sControlId) 
     { 
      return ctlRoot; 
     } 
     // loop the child controls of this parent control and call recursively. 
     foreach (Control ctl in ctlRoot.Controls) 
     { 
      Control ctlFound = FindControlRecursive(ctl, sControlId); 
      // if we found the control, return it. 
      if (ctlFound != null) 
      { 
       return ctlFound; 
      } 
     } 
     // we never found the control so just return null. 
     return null; 
    } 

 FormViewEdit.HeaderTemplate = new FormViewEditTemplate(ListItemType.Header, editXmlForm); 
     FormViewEdit.EditItemTemplate = new FormViewEditTemplate(ListItemType.EditItem, editXmlForm); 
     FormViewEdit.FooterTemplate = new FormViewEditTemplate(ListItemType.Footer, editXmlForm); 
     FormViewEdit.ItemUpdating += new FormViewUpdateEventHandler(FormView1_ItemUpdating); 

     EditFormView.SelectCommand = "SELECT * FROM " + UniqueTable + " WHERE " + PrimaryKey + "=" + ident; 
EditFormView.DataBind(); 

}

protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) 
    { 
     //TODO get all new values and make query string.    
     EditFormView.UpdateCommand = "UPDATE " + UniqueTable + " SET bla_Opis='" + e.NewValues["bla_Opis"] + "' WHERE " + PrimaryKey + "=" + ident; 
     EditFormView.Update(); 
     EditFormView.DataBind(); 
    } 

答えて

0

問題が見つかりました。私は無作為に生成されたidをタップパネルのために使用しました。すべてのポストバックで新しいIDを取得し、古いデータは新しい値をバインドするコントロールを見つけられませんでした。

tapPanel.ID = Guid.NewGuid()。ToString();

関連する問題