下拉列表面临的问题 [英] Problem facing with dropdownlist

查看:52
本文介绍了下拉列表面临的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Techies,

我正在为我的问题寻找解决方案.我在项目中使用了两个下拉列表.假设一个是ddlItemCode,另一个是ddlItemName.用户可以在此处从Itemcode或ItemName中进行选择.如果他从ddlItemCode中选择一个项目,则相应的项目名称将被加载到ddlItemName中.如果他从ddlItemName中选择了该项目,则相应的项目代码将被加载到ddlItemCode中.当我们使用常规dropdownlist时,这很容易.但是在这里,我必须使用级联的dropdownlist.我可能会知道.如果我选择一个ddlItemCode,它将在ddlItem中加载相应的项目.但它只会加载选定的项目名称(下拉列表中只会包含该项目名称,而不会包含其他名称).我希望所有项目都应加载,并且所选项目应显示在ddlItem中.那可能吗?如果是,怎么办?如果任何人共享上述要求的代码,将对您有所帮助.

如果上述问题仍不清楚,请回复并提供评论,我们将很乐意提供更多信息.

提前非常感谢

Hello Techies ,

I am looking for a solution for my problem. I am using two dropdownlist in my project. Assume one is ddlItemCode and the other is ddlItemName. Here the user can select from both Itemcode or ItemName . If he select an item from ddlItemCode the corresponding Itemname will be load in the ddlItemName.And if he select the item from ddlItemName the corresponding Itemcode will be loaded in the ddlItemCode. It is easy when we use normal dropdownlist . But here I have to use the cascading dropdownlist . It will be possible i Know. Here if i select an ddlItemCode it will load the corresponding item in the ddlItem. But it will only load the selected items name (only that item name will be in the dropdown, no other). I want all of the items should be loaded and the selected Item should display in the ddlItem. Is that possible? If yes How ? It will be helpfull if any one of you share the code for the above requirement.

If the question above isn''t completely clear, please reply with a comment and I will be happy to provide the extra information.

Thanks a lot in advance

推荐答案

如果我理解正确,请看下面的示例:

1. aspx文件:

If I understood you right, look into this example:

1. aspx file:

<br />
<pre><asp:DropDownList runat="server" ID="ddlItemName" AutoPostBack="true"<br />
           onselectedindexchanged="ddlItemName_SelectedIndexChanged"><br />
           <asp:ListItem Text="Item1" Value="1"></asp:ListItem><br />
           <asp:ListItem Text="Item2" Value="2"></asp:ListItem><br />
           <asp:ListItem Text="Item3" Value="3"></asp:ListItem><br />
           <asp:ListItem Text="Item4" Value="4"></asp:ListItem><br />
       </asp:DropDownList><br />
       <asp:DropDownList runat="server" ID="ddlItemCode" AutoPostBack="true"<br />
           onselectedindexchanged="ddlItemCode_SelectedIndexChanged"><br />
           <asp:ListItem Value="Item1" Text="1"></asp:ListItem><br />
           <asp:ListItem Value="Item2" Text="2"></asp:ListItem><br />
           <asp:ListItem Value="Item3" Text="3"></asp:ListItem><br />
           <asp:ListItem Value="Item4" Text="4"></asp:ListItem><br />
       </asp:DropDownList</pre><br />
<br />



2. aspx.cs文件:



2. aspx.cs file:

<br />
<pre>public partial class Dropdowns : System.Web.UI.Page<br />
{<br />
    protected void Page_Load(object sender, EventArgs e)<br />
    {<br />
    }<br />
    protected void ddlItemName_SelectedIndexChanged(object sender, EventArgs e)<br />
    {<br />
        ddlItemCode.SelectedValue = ddlItemName.SelectedItem.Text;<br />
    }<br />
    protected void ddlItemCode_SelectedIndexChanged(object sender, EventArgs e)<br />
    {<br />
        ddlItemName.SelectedValue = ddlItemCode.SelectedItem.Text;<br />
    }<br />
}</pre><br />


这篇关于下拉列表面临的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆