Hi all, I have a situation where on a page there are 7-8 dropdowns, which have large amount of data to be binded. I have a radiobutton list having 2 choices and on selecting any of them, the i get the data from cache and bind all the dropdowns which takes about 6-7 seconds.But, i dont use all the dropdown everytime as basic functionality is based on a date range. So i was thinking , if i could load the dropdown on demand, i.e. on click of dropdown arrow, i would bind the dropdown, the it would be better and user does not have to wait for those 6-7 seconds while switching between th radiobuttonlist choices. i tried calling a JS fuction on dropdown's onClick and from there firing one button's event. I am getting the data populated on dropdown's click but, the dropdown gets collapsed as soon as the data is binded, and user have to click again to select from dropdownlist items.I was just wondering if anyone can give me an idea so that the dropdown wont collapse and stays after binding, or else a full idea of lazy loading of the dropdown.I have also specified some of my code from my POC.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/ xhtml1- transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function load() {
//debugger;
var dropdown = document.getElementById('DropDownList1');
var ln = dropdown.options.length;
if (ln == 0) {
var btn = document.getElementById('Button1');
btn.click();
}
dropdown.click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"/>
<div>
<asp:DropDownList ID="DropDownList1" runat="server" onClick="javascript:load();">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" Style="display: noone;"/>
</div>
</form>
</body>
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
ArrayList arr = new ArrayList();
arr.Add("Item1");
arr.Add("Item2");
arr.Add("Item3");
DropDownList1.DataSource = arr;
DropDownList1.DataBind();
}
}
</html>