2017-06-29 642 views
0

我想强制用户更改第一个下拉列表的选择如果他/她在第二个下拉列表中选择了特定值名单。Asp .NET创建值从另一个下拉列表中检查下拉列表

<asp:DropDownList ID="ddlGxP" runat="server" CssClass="stdDropdownSmall" OnSelectedIndexChanged="ddlGxP_SelectedIndexChanged" AutoPostBack="true" /> 

< 其他 { } 以上是第一个下拉列表,其中用户应该从“ddlGxP”

选择值以下是第二个下拉列表,我需要要在用户进行选择时进行检查,我必须检查第一个下拉列表。

<div class="divStandard"> 
    <asp:Label ID="Label23" runat="server" CssClass="stdLabel">nalized Method <span class="mandatory"> *</span></asp:Label> 

    <asp:DropDownList ID="ddlFinalizedMethod" runat="server" CssClass="stdDropdown" /> 
    <asp:CustomValidator ID="cvFinalizedMethod" runat="server" ControlToValidate="ddlFinalizedMethod" InitialValue="0" OnServerValidate="cvFinalizedMethod_ServerValidate" 
     CssClass="RequiredFieldError" ErrorMessage=" ! Please select another GxP Standard" /> 
    } else { 
    <asp:TextBox ID="txtFinalizedMethodDisabled" runat="server" CssClass="stdTextboxSmallDisabled" Enabled="false" /> 
    } 

</div> 

回答

1

我没有足够的声望,所以这里是我的评论。

我只是想用基本术语来说明问题。 您的设计视图由两个下拉列表组成。 您在dropdownlist1上做出选择,其selectedindexchanged被触发执行某种操作。

您现在在dropdownlist2上做出选择,触发其selectedindexchanged并对dropdownlist1执行某种操作,可以更改其内容或选定的值;

对于等待而言,由于忘记了某些事情,我犯了一些简单的错误;

答案!!!!

<body> 
<form id="form1" runat="server"> 
<div> 
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div> 
<div> 
    <asp:DropDownList ID="DropDownList1" runat="server"> 
    </asp:DropDownList> 
    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" 
     onselectedindexchanged="ddl2_selectindexchange"> 
    </asp:DropDownList> 
</div> 
</form> 
</body> 


protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!Page.IsPostBack) 
    { 
     List<string> str = new List<string>(); 
     str.Add("red"); 
     str.Add("blue"); 
     str.Add("black"); 

     List<string> str2 = new List<string>(); 
     str2.Add("red"); 
     str2.Add("blue"); 
     str2.Add("black"); 

     DropDownList1.DataSource = null; 
     DropDownList1.DataSource = str; 
     DropDownList1.DataBind(); 
     DropDownList2.DataSource = null; 
     DropDownList2.DataSource = str2; 
     DropDownList2.DataBind(); 

    } 
} 

protected void ddl2_selectindexchange(object sender, EventArgs e) 
{ 
    DropDownList ddl = new DropDownList(); 
    ddl = sender as DropDownList; 

    ListItem li = new ListItem(); 
    li = ddl.SelectedItem; 
    string s = li.Text; 
    Label1.Text = s; 
} 
+0

是的,这是正确的。我试图找到例子,但没有运气。你可以帮我吗? – Mindan

+0

酷我现在可以对我的答案发表评论 – Bernardo

+0

ddls的值也是在运行时在页面加载时动态设置的 – Bernardo