0

我正在使用工具箱控件(例如文本框、下拉列表)验证用户输入,我希望当用户在下拉列表中选择一个选项时,使其显示或隐藏其下方的上传控件。

例如,在下面的代码中被选为孤独工作作为是答案时,我希望孤独的工作过程文档的文件上传控制要显示在下面的显示,但如果它是一个否答案,我不希望将文件上传到控制展示。

任何帮助将不胜感激。谢谢

  <td class="question">
                             Lone Working:
                    </td>
                    <td>
                        <asp:DropDownList ID="DDLONE" runat="server" Width="150px" 
                            OnSelectedIndexChanged="DDLONE_SelectedIndexChanged">
                            <asp:ListItem Text="Yes"></asp:ListItem>
                            <asp:ListItem Text="No"></asp:ListItem>
                        </asp:DropDownList>
                        <span class="mandatory">*</span>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator27" runat="server" ControlToValidate="DDLONE" ErrorMessage=" Required." InitialValue="Please select one..." ForeColor="Red" SetFocusOnError="true"></asp:RequiredFieldValidator>
                          </td>
                </tr>
                <tr>
                          <td class="question">
                        Lone Working Company Procedure:
                        </td>
                          <td>
                        <asp:AsyncFileUpload ID="AsyncFileUpload3" runat="server" UploaderStyle="Traditional"
                            PersistedStoreType="Session" CssClass="answer" style="float:left" PersistFile="True" CompleteBackColor="#C3D021" />
                        <div class="mandatory" style="display:inline">*</div>
                      <%--- <asp:RequiredFieldValidator ID="AsyncFileUpload3_RequiredFieldValidator" runat="server" 
                            ErrorMessage=" Required."
                            ForeColor="Red"
                            ControlToValidate="AsyncFileUpload3"></asp:RequiredFieldValidator>
                        <asp:TextBox ID="txtUplLone" runat="server" style="display:none" MaxLength="0" /> ---%>
4

1 回答 1

1

您可以尝试使用此代码

1 Add AutopostBack="true"
<asp:DropDownList ID="DDLONE" runat="server" Width="150px" 
                            OnSelectedIndexChanged="DDLONE_SelectedIndexChanged" AutopostBack="true">


2

 protected void DDLONE_SelectedIndexChanged(object sender, EventArgs e)
 {
    if(DDLONE.SelectedItem.Text == "Yes")//Adjust
    {
       AsyncFileUpload3.Visible = true;
    }
    else
    {
       AsyncFileUpload3.Visible = false;
    }    
 }

注意:您必须使用此方法绑定下拉列表(只需一次)

if(! IsPostBack)
{
  //Bind
}

并使用 ViewState 来持久化您的 DropDownList

于 2012-08-30T13:50:33.467 回答