下拉列表中选择的索引已更改

下拉列表中选择的索引已更改

问题描述:

我已经编写了这段代码,但是在运行时它无法正常工作,任何人都可以帮助我

I have written this code but during runtime its not working can anyone help me

protected void ddldocumenttype_SelectedIndexChanged(object sender, EventArgs e)
       {
           if (ddldocumenttype.SelectedItem.Text == "pdf" | ddldocumenttype.SelectedItem.Text == "word")
           {
               txturl.Visible = false;
               fudocs.Visible = true;
           }
           else
           {
               txturl.Visible = true;
               fudocs.Visible = false;
           }
       }

您只需为DropDownList添加AutoPostBack="true",如下所示:

You just need to add the AutoPostBack="true" for the DropDownList as follows:

<asp:DropDownList AutoPostBack="true" ID="ddldocumenttype" runat="server"

            onselectedindexchanged="ddldocumenttype_SelectedIndexChanged">
            <asp:ListItem Text="pdf" Value="pdf" Selected="True"></asp:ListItem>
            <asp:ListItem Text="text"></asp:ListItem>
            <asp:ListItem Text="word"></asp:ListItem>
</asp:DropDownList>



当下拉列表中的选择更改时,这将导致调用OnSelectedIndexChanged 事件处理程序方法.默认情况下,AutoPostBack 设置为"false".



This will cause the OnSelectedIndexChanged event handler method to be invoked, when the selection is changed in the drop down list. By default, the AutoPostBack is set to "false".