Tuesday, 6 September 2011

multiline dropdownlist in asp.net


aspx code:
<head runat="server">
    <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
    function show()
    {
        if(document.getElementById("ddldiv").style.display=='none')
            document.getElementById("ddldiv").style.display='block';
        else
            document.getElementById("ddldiv").style.display='none';
    }
    function makecall(v)
    {
        document.getElementById("hf").value=v;
        document.getElementById("ddldiv").style.display='none';
        document.getElementById("txt").value=v;
        document.getElementById('btn').click();
    }
    document.onclick = check;  
    function check(e)
    {
        var target = (e && e.target) || (event && event.srcElement);
        if(target.id!='')
            if(!target.id.match("spanid")||!target.id=="btn")
                document.getElementById("ddldiv").style.display='none';
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="divarea" style="width:100%;height:100%;">
        <asp:TextBox ID="txt" runat="server" onclick="javascript:show();" autocomplete="off"></asp:TextBox>
        <img src="images/dropdown_arrow.PNG" onclick="javascript:show();" alt="ddl" style=" margin-bottom: -5px;margin-left: -24px;"/>
        <div id="ddldiv" runat="server" style="display:none;z-index:9999;position:absolute;background:white;"></div>
        <asp:Button ID="btn" runat="server" Text="through own" style="visibility:hidden;" onclick="btn_Click" />
        <br /><br /><br /><br />
        <asp:Label ID="lbl" runat="server"></asp:Label>
        <asp:HiddenField ID="hf" runat="server" />
    </div>
    </form>
</body>

aspx.cs code:

protected void Page_Load(object sender, EventArgs e)
    {
        fillddl();
    }
    private void fillddl()//process your logic to fill the ddl
    {
        ddldiv.InnerHtml = "";
        StringBuilder sb = new StringBuilder();
        sb.Append("<table>");
        for (int i = 0; i < 5; i++)
        {
            sb.Append("<tr>");
            for (int j = 0; j < 5; j++)
            {
                string t = (i + 1).ToString() + (j + 1).ToString();
                sb.Append("<td><span id='spanid" + t + "' onclick='javascript:makecall(" + t + ")' >" + t + "</span>&nbsp;&nbsp;</td>");
            }
            sb.Append("</tr>");
        }
        sb.Append("</table>");
        ddldiv.InnerHtml = sb.ToString();
    }
    protected void btn_Click(object sender, EventArgs e)
    {
        lbl.Text = "you selected" + hf.Value;
    }


Tag: multiline dropdownlist asp.net, multiline dropdownlist in asp.net, multiselect dropdown list asp.net, multiselect dropdown list in asp.net, multiselect dropdownlist asp.net

No comments:

Post a Comment

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute                             '{ "@id": 1001, "@name&q...