2011-12-12 17 views
0

私は、テーブルを格納する更新パネルを持っています。テーブルには、動的にさまざまなプロパティフィールドの入力要素の行を生成します。.net updatepanelで動的表の行を更新するにはどうすればよいですか?

foreach (DataRow propertyRowToDraw in temporaryTableOfProperties.Rows) 
    { 
     // Create the property row 
     TableRow propertyRow = new TableRow(); 

     // Create the first cell, and give it a value of the property ID, but don't display it 
     TableCell propertyIDColumn = new TableCell(); 
     propertyIDColumn.Text = propertyRowToDraw["PropertyId"].ToString(); 
     propertyIDColumn.Visible = false; 
     propertyRow.Cells.Add(propertyIDColumn); 

     // Create the second cell and give it a value of the text, or prompt, for that property 
     TableCell propertyNameColumn = new TableCell(); 
     propertyNameColumn.ID = "propertyName" + propertyRowToDraw["PropertyId"].ToString(); 
     propertyNameColumn.Text = propertyRowToDraw["Prompt"].ToString(); 
     propertyNameColumn.Width = Unit.Percentage(15); 
     propertyRow.Cells.Add(propertyNameColumn); 


     // Not sure what this does 
     TableCell propertyHiddenValuesColumn = new TableCell(); 
     propertyHiddenValuesColumn.ID = "hiddenValues" + propertyRowToDraw["PropertyId"].ToString(); 
     propertyHiddenValuesColumn.Attributes.CssStyle.Add("display", "none"); 
     HiddenField hiddenPropertyDataType = new HiddenField(); 
     hiddenPropertyDataType.Value = propertyRowToDraw["DataType"].ToString(); 
     propertyHiddenValuesColumn.Controls.Add(hiddenPropertyDataType); 
     propertyRow.Cells.Add(propertyHiddenValuesColumn); 

     // Create a new cell for the property data type 
     TableCell propertyDataTypeColumn = new TableCell(); 
     propertyDataTypeColumn.ID = "propertyDataType" + propertyRowToDraw["PropertyId"].ToString(); 

     // Create a dropdown list for the property data type for this cell 
     DropDownList inquiryTypeSelection = new DropDownList(); 
     inquiryTypeSelection.Width = Unit.Percentage(100); 

     // Cast it to the propertyDataType enum and do a switch to determine what items to add to the dropdown 
     switch ((Altec.Framework.PropertyDataType)Convert.ToInt32(propertyRowToDraw["DataType"])) 
     { 
      case PropertyDataType.Date: 
       inquiryTypeSelection.Items.Add(new ListItem("Exactly", "2")); 
       inquiryTypeSelection.Items.Add(new ListItem("Greater Then", "3")); 
       inquiryTypeSelection.Items.Add(new ListItem("Less Then", "4")); 
       inquiryTypeSelection.Items.Add(new ListItem("Range", "5")); 
       break; 

      case PropertyDataType.Boolean: 
       inquiryTypeSelection.Items.Add(new ListItem("Exactly", "2")); 
       break; 

      case PropertyDataType.Currency: 
       inquiryTypeSelection.Items.Add(new ListItem("Any", "1")); 
       inquiryTypeSelection.Items.Add(new ListItem("All", "0")); 
       inquiryTypeSelection.Items.Add(new ListItem("Greater Then", "3")); 
       inquiryTypeSelection.Items.Add(new ListItem("Less Then", "4")); 
       inquiryTypeSelection.Items.Add(new ListItem("Range", "5")); 
       break; 

      case PropertyDataType.Double: 
       inquiryTypeSelection.Items.Add(new ListItem("Any", "1")); 
       inquiryTypeSelection.Items.Add(new ListItem("All", "0")); 
       inquiryTypeSelection.Items.Add(new ListItem("Greater Then", "3")); 
       inquiryTypeSelection.Items.Add(new ListItem("Less Then", "4")); 
       inquiryTypeSelection.Items.Add(new ListItem("Range", "5")); 
       break; 

      case PropertyDataType.String: 
       inquiryTypeSelection.Items.Add(new ListItem("Any", "1")); 
       inquiryTypeSelection.Items.Add(new ListItem("All", "0")); 
       break; 
     } 

     // Add the dropdown to the cell and then add the cell to the row 
     propertyDataTypeColumn.Width = Unit.Percentage(15); 
     propertyDataTypeColumn.Controls.Add(inquiryTypeSelection); 
     propertyRow.Cells.Add(propertyDataTypeColumn); 


     // Create the cell that will hold the input box 
     propertyIDColumn = new TableCell(); 
     propertyIDColumn.ID = "propertyInputColumn" + propertyRowToDraw["PropertyId"].ToString(); 

     // Create the textbox input that will hold the search value for that property row 
     TextBox propertyTextInput = new TextBox(); 
     propertyTextInput.ID = "propertyInputText" + propertyRowToDraw["PropertyId"].ToString(); 
     propertyIDColumn.Controls.Add(propertyTextInput); 
     propertyTextInput.Width = Unit.Percentage(92); 
     // Add it to the row 
     propertyRow.Cells.Add(propertyIDColumn); 

     // Add the row to the overall table 
     docTypePropertiesTable.Rows.Add(propertyRow); 


    } 

私は、UpdatePanelのを介してサーバー側でこれらのテキストボックス(propertyTextInput)への値の入力を得るだろうか?何らかの理由で、たとえviewstatemode = enabledにしても、テーブルが返ってきたときにviewstateにテーブルが表示されません。

ページ上の他の入力要素に基づいて行数が可変であるため、行を動的に生成する必要があります。

新鮮なアイデア。

答えて

0

動的に追加されたコントロールを使用すると、すべてのポストバックでが読み取られたである必要があります。そうでないと、サーバー側でアクセスできなくなります。

コントロールを1回だけ追加していますか?IsPostBack?はいの場合は!IsPostBackチェックを削除し、すべてのポストバックのコントロールを読み取ります。

そうでない場合は、更新パネルのaspxコードを投稿してください。

0

要素の有限の行、たとえば10がある場合は、設計時にテーブルに10の空白行を作成し、ページから動的にそれらを読み込むことができます。動的な行数が必要な場合は、viewstateに日付を格納する必要があると思います。同じ問題がありますので、サンプルコードを少しでも投稿できるはずです。

関連する問題