TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Get Data Using Web Services and JavaScript
Satyajeet Kumar
Mar 28
2016
Code
1.4
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System.Data;
using
System.Data.SqlClient;
using
System.Configuration;
using
System.Web.Script.Serialization;
[WebMethod(EnableSession =
true
)]
public
List<string> GetData(string VALUE1, string VALUE2)
{
SQLHelper objHelper =
new
SQLHelper();
IDataReader reader = null;
List<string> result =
new
List<string>();
try
{
string strQuery =
"Select * from TABLE where VALUE='"
+ VALUE1 +
"' and VALUE='"
+ VALUE2 +
"' "
;
reader = objHelper.getReaderFromQuery(strQuery);
while
(reader.Read())
{
for
(
int
i = 0; i < reader.FieldCount; i++)
result.Add(Convert.ToString(reader[i]));
}
}
catch
(Exception ex)
{
}
finally
{
if
(reader != null)
reader.Close();
}
return
result;
}
<script type=
"text/javascript"
language=
"javascript"
>
function getWebData(value1, value2)
{
myService.GetData(value1, value2, bindData, null, null);
}
function bindData(result)
{
var Data=
""
;
if
(result==
''
)
{
document.getElementById(
'divDetails'
).innerHTML=
'No Record Found!'
;
}
else
{
for
(var i=0;i<result.length;i=i+4)
{
if
((i/3)%3==0)
Data=Data+
'<tr class="Purple"><td align="center">'
+result[i]+
'</td><td>'
+result[i+1]+
'</td><td align="right">'
+result[i+2]+
'</td><td align="Center">'
+result[i+3]+
'</td></tr>'
;
else
if
((i/3)%3==1)
Data=Data+
'<tr class="Blue"><td align="center">'
+result[i]+
'</td><td>'
+result[i+1]+
'</td><td align="right">'
+result[i+2]+
'</td><td align="Center">'
+result[i+3]+
'</td></tr>'
;
else
if
((i/3)%3==2)
Data=Data+
'<tr class="Green"><td align="center">'
+result[i]+
'</td><td>'
+result[i+1]+
'</td><td align="right">'
+result[i+2]+
'</td><td align="Center">'
+result[i+3]+
'</td></tr>'
;
else
Data=Data+
'<tr class="Gray"><td align="center">'
+result[i]+
'</td><td>'
+result[i+1]+
'</td><td align="right">'
+result[i+2]+
'</td><td align="Center">'
+result[i+3]+
'</td></tr>'
;
}
document.getElementById(
'divDetails'
).innerHTML = Data;
}
}
</script>
.Net
Asp.net
C#
Javascript
Web Service