我有以下下拉菜单
<li><span>State: <asp:DropDownList ID="ddlAppState" runat="server">
</asp:DropDownList></span></li>
它使用以下函数在页面加载()上填充
private void ddlAppState_DataBind()
{
string myXMLfile = Server.MapPath("~/App_Data/ActiveStates.xml");
System.Data.DataSet dsStudent = new System.Data.DataSet();
dsStudent.ReadXml(myXMLfile);
ddlAppState.DataSource = dsStudent;
ddlAppState.DataValueField = "StateID";
ddlAppState.DataTextField = "StateName";
ddlAppState.DataBind();
}
最初下拉列表中的值是“--------”,但在后端它映射到“FD”我想验证是否选择了“-----”,如果我通过执行 ddlAppState 获得其值。 SelectedValue.ToString() 是一个字符串“FD”,然后我不想调用 button 的 onlick 函数。
按钮 OnClick
<asp:Button Style="left: 0px; position: relative" ID="btnSearch" runat="server" CausesValidation="False"
CssClass="lbSearch closeform" Text="Search" Width="80px" OnClick="btnSearch_Click" >
</asp:Button></div>
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
if (ddlAppState.SelectedValue.ToString() == "FD" && ddlAppMode.SelectedValue.ToString() == "S")
{
SelectState.Text = " Please Select State ";
return;
}
SelectState.Text = "";
BindGridViewZipConfirmation1();
// clearFields(); }
关于如何完成的任何想法。谢谢你