Click here to Skip to main content
13,095,921 members (55,453 online)
Rate this:
Please Sign up or sign in to vote.
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.

Posted 26-Jun-12 19:32pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 27 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100