Highlight asp.net list for extension

I have an ASP.NET related data dropdown that populates based on the contents of a text field. After it is filled in, I would like to automatically expand the drop-down list so that the user understands that they need to make a choice and do not need to click on the drop-down list to expand it. It seems that there is no property or method.

EDIT: After I tried the Ed B example, I was still stuck. My ddl's id is 'ctl00_ContentPlaceHolder9_ddlContact'. If I put the following in the onclick event of the button, it works fine, the drop-down menu expands beautifully:

    document.getElementById('ctl00_ContentPlaceHolder9_ddlContact').size=10;

However, the following code in the Databound event for ddl shows a warning, but does not open the dropdown menu:

string script = "<SCRIPT LANGUAGE='JavaScript'> ";
    script += "alert('expanding');document.getElementById('ctl00_ContentPlaceHolder9_ddlContact').size=10 </SCRIPT>";
    ClientScript.RegisterClientScriptBlock(GetType(), "Dropdown", script);
+3
source share
3 answers

Summary: You cannot expand the vanilla drop-down list. See this discussion for more information: Is it possible to open a drop-down list using jQuery . However, there are some methods that may be acceptable.

One approach (albeit a little cheeky) is to expand the drop-down list to display more elements at once. Default item , , . , DDL ( ), 1 ( "" DDL). :

<asp:DropDownList runat="server" ID="ddlColors" 
                  onmouseover="this.size=3;" 
                  onmouseout="this.size=1">
    <asp:ListItem>Red</asp:ListItem>
    <asp:ListItem>Green</asp:ListItem>
    <asp:ListItem>Blue</asp:ListItem>
</asp:DropDownList>

- JavaScript . , script DOM- CSS, , .

!

+2

. 1.

, open_ddl .

<script language="javascript">    
function open_ddl()
    {
    document.getElementById("select1").size=5
    }

    function close_ddl()
    {
    document.getElementBById("select1").size=1
    }

    </script>

    Worst President Ever:
    <select id="Select2" runat="SERVER" onmouseover="open_ddl()" onmouseout="close_ddl()">
                     <option value="0" >Obama</option>
                     <option value="1" >Carter</option>
                     <option value="2" >Nixon</option>
                     <option value="3" >Clinton</option>
    </select>
0

.

, javascript, script DataBound. ( jQuery)

script+=$("#ctl00_ContentPlaceHolder9_ddlContact").attr("multiple", "multiple");

Or instead, you can take out javascript and just add some attributes directly to the markup. So do this:

DropDownList1.Attributes.Add("multiple","multiple");
0
source

Source: https://habr.com/ru/post/1761987/


All Articles