Fotolia_13157710_XS

ASP.NETでFormViewを使ったときに、DropDownを手動で作成していると、データーバインド時にエラーになります。

普通にFormView以外でやった場合は問題無いのですが、なぜかFormViewの中ではエラーになります。

項目自体もデーターバインドしていれば問題ないのですが・・・

そこで、トリッキーですが、解決法を。

SQLデーターソースを空で作成します(SQLデーターソースでなくてもOK)

   1:  SELECT '' as Text, '' as Value

のような何も返さないSQL文を作成します。

   1:  AppendDataBoundItems="True"

あとはDropDownListの「手動」で追加した項目を消さないように、

AppendDataBoundItemsをTrueに設定します。

(DropDownList1.Items.Addも使用可能です。)

これでデーターバインドが可能になります。

Popularity: 4% [?]

Share and Enjoy:
  • Print
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • email
  • RSS
  • Tumblr
  • Twitter
  • Yahoo! Bookmarks
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Google Analytics Alternative