仅在单击时加载下拉列表

时间:2017-09-25 10:25:04

标签: asp.net

我的页面中有1个独立下拉列表和3个相关下拉列表。加载所有ddlvalues最初需要更多时间,甚至对于每个ddl索引更改,其他相关ddl需要更多时间来加载..

请帮我找到解决方案。 我尝试加载我的页面最初没有任何值,除了--All--所有下拉菜单中都有索引0.只有当点击下拉列表时,它应该从数据集中加载数据,如果需要,可以使用之前的ddl值。

然后我找到了' Onclick' ddl中缺少选项。所以我用过    Math.pow(2,4); >16 Math.pow(2,4.1); >17.148375400580687 我不确定将此代码放在ma页面中的哪个位置。 以及那个要编写的java脚本..

你能帮帮我吧 下面是我的代码...... ------------我的设计页面代码------------------

ddlGM.Attributes.add("OnClick",javascriptfunction)

------------我的.cs页面代码-----------------

     <script type="text/javascript">
    //    $(dropdownloads).click(function() {
    //    clickHiddenButton();
    //});
     //$(document).ready(function () {

        function clickHiddenButton() {
        //var ddl = dropdownloads.getElementById('ddlGM');
        //if (ddl.click) 

           var btn = dropdownloads.getElementById('btnHidden');
            btn.click();

    }
    //})
</script>


<td>
  <asp:Label ID="GM"  runat="server" Text="Global Market" ></asp:Label></td>
<td>
 <asp:DropDownList runat="server" ID="ddlGM"    
     Width="150px" AutoPostBack="True" class="dropdownloads"
    onselectedindexchanged="ddlGM_SelectedIndexChanged" style="height:22px">
    <asp:ListItem Value=0 Text="All"></asp:ListItem></asp:DropDownList>
         <div style="display: none;" >
                    <asp:Button ID="btnHidden" runat="server" Text="Button" OnClick="btnHidden_Click"  />

                </div></td>

 <td ><asp:Label ID="Horizontal" runat="server" Text="Horizontal"></asp:Label></td>  
 <td>< asp:DropDownList ID="ddlHori" runat="server" AutoPostBack="True" Width="150px" onselectedindexchanged="ddlHori_SelectedIndexChanged">
<asp:ListItem Value=0 Text="All"></asp:ListItem></asp:DropDownList></td>

<td>< asp:Label ID="BU" runat="server" Text="BU"></asp:Label></td>   
<td>< asp:DropDownList ID="ddlBU" runat="server" AutoPostBack="True" Width="150px" onselectedindexchanged="ddlBU_SelectedIndexChanged">
<asp:ListItem Value=0 Text="All"></asp:ListItem></asp:DropDownList></td>

<td>< asp:Label ID="SBU1" runat="server" Text="SBU"></asp:Label></td>
<td>< asp:DropDownList ID="ddlSBU1" runat="server" AutoPostBack="True" Width="150px" onselectedindexchanged="ddlSBU1_SelectedIndexChanged">
<asp:ListItem Value=0 Text="All"></asp:ListItem></asp:DropDownList></td>

1 个答案:

答案 0 :(得分:0)

你的意思是这样的:

If(buttonClicked) {
   // Sets the data in the ddl
   dropdownList.DataSource = yourDataSource;
} else {
   // Clears (removes) all ites in the ddl
   dropdownList.Items.Clear();
}

或者,如果您的意思是从1 ddl中选择一个项目:

foreach(ListItem item in ddl.Items) {
    // If the value is selected in the dropdownlist
    If(item.Selected) {
       // Sets the data in the ddl
       dropdownList.DataSource = yourDataSource;
    }
}