Thursday, 15 September 2011

div behaves like a dropdownlist in asp.net


aspx.cs code:
protected void Page_Load(object sender, EventArgs e)
{
  string d = "";
  if (true)//means ds.tables.rows.count>0;
  {
    d = "<table width='133px' border='1px'>";
    for (int i = 0; i < 10; i++)
    {
      string s = "FirstLineSecondLine";
      d += "<tr><td onclick='javascript:bindTextBox(" + i + ",\"" + s + "\");'>";
      if (s.Length > 9)
      {
        d += "<a>" + s.Substring(0, 9) + i.ToString() + "<br />&nbsp;&nbsp;";
        d += s.Substring(9, 10) + i.ToString() + "</a>";
      }
      else
        d += s + i.ToString();
      d += "</td></tr>";
}
d += "</table>";
divContent.InnerHtml = d;
  }
}

aspx code:

<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function showDiv()
{
    document.getElementById("divContent").style.visibility='visible';
}
document.onclick = check;
function check(e)
{
    var target = (e && e.target) || (event && event.srcElement);
    if(target.id=="divTotalBody")
        document.getElementById("divContent").style.visibility='hidden';
    if(target.id=="")
        document.getElementById("divContent").style.visibility='hidden';
}
function bindTextBox(pkvalue,d)
{
    document.getElementById("txtData").value=d;
    document.getElementById("hfValue").value=pkvalue;
    document.getElementById("divContent").style.visibility='hidden';
}
</script>
<style type="text/css">
#divContent {float: none !important;}
#divContent td {color: #B13F03 !important;text-decoration: underline;}
#divContent td:hover {background:#F6CEE3 !important;text-decoration: none;}
</style>
</head>
<body>
 <form id="form1" runat="server">
 <div id="divTotalBody">
 <asp:TextBox ID="txtData" runat="server" Text="Select" onclick="javascript:showDiv();" ReadOnly="true"></asp:TextBox>
 <img id="imgDown" src="../dropdown_arrow.PNG" alt="" style="margin-bottom:-5px;margin-left:-24px;" onclick="javascript:showDiv();"/>
 <div id="divContent" runat="server" style="visibility:hidden;width:150px;z-index:9999;position:absolute;background:white;cursor:pointer;overflow-y:auto;height: 190px;"></div>
 <asp:HiddenField ID="hfValue" runat="server" />
 </div>
 </form>
</body>
</html>

Tag: div behaves like a dropdownlist in 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...