Friday, August 28, 2009

How to fill a javascript array from a database using inline code

The On Demand Global Workforce - oDesk


protected void Page_Load(object sender, EventArgs e)
{
Session.Clear();
DataSet ds = new DataSet();
if (Session["dt"] == null)
{
ds = c();
}
else
{
ds = Session["dt"] as DataSet;
}
foreach (DataRow dr in ds.Tables[0].Rows)
{
this.ClientScript.RegisterArrayDeclaration("myArray", "'" + dr["Address"].ToString() + "'");
}
}

html xmlns="http://www.w3.org/1999/xhtml">
head runat="server">
title>Untitled Pagetitle>
head>
body>
form id="form1" runat="server">
div>
input type="text" id="indexText" />
input type="button" id="showButton" value="Show Array Element By Index"onclick="ShowItem(document.getElementById('indexText').value);" />
div>
form>
body>
script type="text/javascript">
function ShowItem(index)
{
alert('myArray['+index+'] = ' + myArray[index]);
//alert(myArray[index]);
}script>
html>

Find server control in another page


script type="text/javascript">
function ClientClose()
{
$find("%= RadAjaxManager1.ClientID %>").ajaxRequest();
}
/script>

Show/Hide controls

function ShowCalendar()
{

 document.getElementById('<%= Calendar1.ClientID %>').style.display = 'none'
}
function HideCalendar()
{
 document.getElementById('<%= Calendar1.ClientID %>').style.display = ''

}





No comments:

Post a Comment