我有Dropdownlist,其值字段和文本字段在运行时绑定。 它具有--select--
作为值为0
的第一项,其余值在运行时绑定。Asp.net中的Dropdownlist验证使用必需的字段验证程序
我已经给validaton组对照和验证为"g1"
和Intialvalue=0
但还是在页面回发,即使我选择--select--
选项。
<asp:DropDownList AutoPostBack="true" CssClass="dropdown" ValidationGroup="g1"
ID="ddlReportType" runat="server"
OnSelectedIndexChanged="ddlReportType_SelectedIndexChanged"></asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="ddlReportType" ID="RequiredFieldValidator1"
ValidationGroup="g1" CssClass="errormesg" ErrorMessage="Please select a type"
InitialValue="0" runat="server" Display="Dynamic">
</asp:RequiredFieldValidator>
而后面的代码绑定的下拉
ddlReportType.Items.Clear();
ddlReportType.DataSource = dt.Tables[0];
ddlReportType.DataTextField = "ReportType";
ddlReportType.DataValueField = "ReportTypeID";
ddlReportType.DataBind();
ddlReportType.Items.Insert(0, new ListItem("--Select--", "0"));
//ddlReportType.Items[0].Value = "0";
ddlReportType.SelectedIndex = 0;
U可以看到我更新的帖子 – 2011-03-15 11:21:39
请确认你已经把上面的代码中,如果(!的IsPostBack){}方法 – 2011-03-15 11:51:37
是的,它是里面,如果(!的IsPostBack) {}和我打电话给代码behid一些单选按钮更改事件 – 2011-03-16 04:53:54