- PR -

FormView内のDropDownListの検証方法

1
投稿者投稿内容
ぷり
ベテラン
会議室デビュー日: 2008/02/22
投稿数: 60
投稿日時: 2008-09-25 09:46
お世話になります。

現在、webアプリをVB2005にて作成しております。

FormView内にあるDropDownListの検証方法を教えて下さい。


FormView内にDropDownListを2つ置きました。

他にTextBoxがいくつかあり、それらのTextBoxにも「RequiredFieldValidator」を設置し、

「ValidationSummary」を置いています。

登録ボタンを押した際にDropDownListで何も選択されていない場合や、

最初に表示させている「選択」の文字の場合にエラー文字を表示させたいです。

TextBoxは検証されますが、DropDownListは検証されません。

「CustomValidator」を使用すると思うのですが、設定方法がわかりません。

宜しくお願いします。

りっきー
会議室デビュー日: 2008/10/30
投稿数: 1
投稿日時: 2008-10-30 00:26
ちょうど私も最近作成中のWebアプリで、DropDownListの未選択検証を実装しました。

このページを参考にClientValidationFunctionプロパティに検証関数を設定しました。

検証関数についてはMSDNを参考にし、DropDownListの選択値がIsValid = trueとしました。
Access
ぬし
会議室デビュー日: 2002/04/08
投稿数: 829
投稿日時: 2008-10-30 06:07
RequiredFieldValidatorで出来ませんか?

コード:

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="" Text="選択" />
<asp:ListItem Value="1" text="Item1" />
<asp:ListItem Value="2" text="Item2" />
<asp:ListItem Value="3" text="Item3" />
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="DropDownList1"
Display="Dynamic"
ErrorMessage="選択してください!">*</asp:RequiredFieldValidator>

<br /><br />

<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Value="0" Text="選択" />
<asp:ListItem Value="1" text="Item1" />
<asp:ListItem Value="2" text="Item2" />
<asp:ListItem Value="3" text="Item3" />
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="DropDownList2"
Display="Dynamic"
ErrorMessage="選択してください!"
InitialValue="0">*</asp:RequiredFieldValidator>



ライブデモ:
http://asp35.com/samples/081030CS-2.aspx
_________________
ASP.NET+Ajaxサンプル集 | JavaScript+Ajaxサンプル集

[ メッセージ編集済み 編集者: Access 編集日時 2008-10-30 06:30 ]
1

スキルアップ/キャリアアップ(JOB@IT)