2017-12-19 9 views
2

ダイナミックasp:テーブルにコントロール(Textboxを例として)にいくつかのバリデータを追加したいと思います。ダイナミックASP:ネットテーブルに必要なバリデータを追加

コード:

foreach (KeyValuePair<string, string> o in Collection) 
    { 
     TableRow Row = new TableRow(); 

     TableCell valueCell = new TableCell(); 
     TableCell Cell = new TableCell(); 
     TextBox txtBox = new TextBox(); 
     TextBox txtBox1 = new TextBox(); 


     txtBox1.ID = o.Key + o.Value; 
       if (o.Value.Contains("Mandatory")) 
       { 
        RequiredFieldValidator req = new RequiredFieldValidator(); 

        req.ErrorMessage = "Required"; 
        req.BorderColor = System.Drawing.Color.Red; 
        req.ControlToValidate = txtBox1.ID; 
        req.Enabled = true; 
        req.Display = ValidatorDisplay.Dynamic; 

        Cell.Controls.Add(req); 
       } 

     valueCell.Controls.Add(txtBox1); 
     Row.Cells.Add(valueCell); 
     Row.Cells.Add(Cell); 
     table.Rows.Add(Row); 
} 

しかし、私はこのエラーを取得しています:ライン上の

" System.Web.UnhandledException in System.web.dll"

Row.Cells.Add(Cell);

あなたは私を助けることができますか?

+1

少なくとも、例外メッセージの詳細を入力してください。 –

+0

この例外についていくつかの詳細を知ることができますか? VSは標準のExceptionウィンドウを開かないためです。 –

+0

簡単な解決策として、 'try/catch'ブロックにコードをラップし、' catch'ブロックにブレークポイントを置くことができます。 –

答えて

0

TexboxとRequireValidatorFieldを含むPanelで問題を解決しました。

Panel p = new Panel(); 
    p.Controls.Add(txtBox1); 
    p.Controls.Add(req); 
    valueCell.Controls.Add(p); 
関連する問題