Click here to Skip to main content
15,667,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all, I need to create a web service to pass the dataset to javascript function. I don't have that much idea in webservice.I wish to know the step by step process. Can anyone help to solve this out.

Thanks in advance.


1 solution

Share this answer
Comments 27-Jun-12 4:24am    
Thank you Vani Kulkarni.
Vani Kulkarni 27-Jun-12 5:01am    
Welcome arun! 27-Jun-12 5:26am    
<%@ Page Language="C#" %>

<%@ Import Namespace="System.Data" %>

<script runat="server">

public static System.Data.DataTable MyMethod(int value)
return GetDataSet(value);

public static System.Data.DataTable GetDataSet(int value)

DataTable dt = new DataTable("Author");
DataRow dr;
dt.Columns.Add(new DataColumn("Id", typeof(Int32)));
dt.Columns.Add(new DataColumn("Author", typeof(string)));

for (int i = 0; i <= 10; i++)
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Author" + i.ToString();
for (int i = 20; i <= 40; i++)
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Author" + i.ToString();

DataView dv = new DataView(dt);
dv.RowFilter = "Id='" + value + "'";

return dv.Table;


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="">
<head id="Head1" runat="server">
<title>Untitled Page</title>

<script language="javascript" type="text/javascript">
function CallMyWebService()
function OnRequestComplete(result)
var str="";
for(var i = 0; i < result.rows.length; i++)

str+=result.rows[i].Author +"<br>";


<form id="form1" runat="server">
<asp:ScriptManager ID="scriptManger1" runat="server"
<asp:ServiceReference Path="~/WebService.asmx" />

<div id="result">
<input type="button" önclick="CallMyWebService();" id="myButton"
value="Call MyWebService" />
if you tried, you likely received some sort of circular reference serialization error to take advantage of this, you will need to add the following to your web.config:

<add name="DataSetConverter"
<add name="DataRowConverter"
<add name="DataTableConverter"


I use the same code. But it is not working. Can u check it Vani.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900