本文介绍了如何在JavaScript中将返回的字符串数组从函数分配给varble的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我在.cs文件中编写了一个返回字符串数组的函数,并在javascript部分中对该函数进行了调用.我必须获取这些返回的函数值并使用lable在对话框中显示使用ajax.我不明白如何在javascript.Olz中重新获得该值.

我写的代码如下.
holiday.aspx

< script language ="javascript" type ="text/javascript">
函数myfuncion(id){
var a = new Array();
a = HolidayApps.RetrieveData(id.toString());
document.getElementById("lblDesc").textContent = a [1] .value;
$(''#dialog'').dialog(''open'');
//alert(a.value);
}
$(function(){
//对话框
$(''#dialog'').dialog({
autoOpen:false,
宽度:600,
按钮:{
确定":function(){
$(this).dialog("close");
},
取消":function(){
$(this).dialog("close");
}
}
});

//对话框链接
$(''#dialog_link'').click(function(){
$(''#dialog'').dialog(''open'');
返回false;
});

//将鼠标悬停在静态小部件上的状态
$(''#dialog_link,ul#icons li'').hover(
函数(){$(this).addClass(''ui-state-hover''); },
函数(){$(this).removeClass(''ui-state-hover''); }
);

});
</script>


holiday.aspx.cs

In my application I have written a function in .cs file which returns an array of string.and I have given call to that function in javascript section.I have to obtain these returned values of function and display in dialog box using lable using ajax.I doesn''t understand how to obain that values in javascript.Plz help me.

The code written by me as follows.
holiday.aspx

<script language="javascript" type="text/javascript">
function myfuncion(id) {
var a=new Array();
a=HolidayApps.RetrieveData(id.toString());
document.getElementById("lblDesc").textContent = a[1].value;
$(''#dialog'').dialog(''open'');
//alert(a.value);
}
$(function () {
//Dialog
$(''#dialog'').dialog({
autoOpen: false,
width: 600,
buttons: {
"Ok": function () {
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});

//Dialog Link
$(''#dialog_link'').click(function () {
$(''#dialog'').dialog(''open'');
return false;
});

//hover states on the static widgets
$(''#dialog_link, ul#icons li'').hover(
function () { $(this).addClass(''ui-state-hover''); },
function () { $(this).removeClass(''ui-state-hover''); }
);

});
</script>


holiday.aspx.cs

public string[] RetrieveData(int id)
    {
        CDisplay objdisplay = new CDisplay();
        string[] objdesc = new string[2];
        objdesc=objdisplay.RetrieveDescription(id);
        return objdesc;
    }




display.cs

公共字符串[] RetrieveDescription(int id)
{
SqlCommand sqlcommand;
SqlConnection sqlconnection;
SqlDataReader sqlreader;
字符串connectionstring =数据源=.\\ SQLEXPRESS; AttachDbFilename = E:\\ HolidayApps \\ App_Data \\ holidaydatabase.mdf;集成安全性= True; Connect Timeout = 30;用户实例= True";
字符串说明= null;

sqlconnection =新的SqlConnection(connectionstring);
sqlcommand = new SqlCommand(从tblHoliday中选择位置,说明,其中hid =" + id,sqlconnection);
sqlconnection.Open();
sqlreader = sqlcommand.ExecuteReader();
string [] arr =新字符串[2];
while(sqlreader.Read())
{
arr [0] = sqlreader ["description"].ToString();
arr [1] = sqlreader ["occation"].ToString();

}
return arr;

}




display.cs

public string[] RetrieveDescription(int id)
{
SqlCommand sqlcommand;
SqlConnection sqlconnection;
SqlDataReader sqlreader;
string connectionstring = "Data Source=.\\SQLEXPRESS;AttachDbFilename=E:\\HolidayApps\\App_Data\\holidaydatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
string description = null;

sqlconnection = new SqlConnection(connectionstring);
sqlcommand = new SqlCommand("Select occation,description from tblHoliday where hid=" + id, sqlconnection);
sqlconnection.Open();
sqlreader = sqlcommand.ExecuteReader();
string[] arr=new string[2];
while (sqlreader.Read())
{
arr[0] = sqlreader["description"].ToString();
arr[1]=sqlreader["occation"].ToString();

}
return arr;

}

推荐答案




这篇关于如何在JavaScript中将返回的字符串数组从函数分配给varble的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 04:22