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
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Omar Kh
NA
301
21.8k
how to retrieve data using ajax in c# ASP.NET ?
Aug 15 2020 2:09 AM
im trying to retrieve data using ajax and bound it to a dropdownlist
i have created a web method in remin.aspx form as follows :
[WebMethod]
public
static
List<senders_list> GetCustomers()
{
string query =
"select c_no, c_name from cust"
;
string constr = ConfigurationManager.ConnectionStrings[
"myConnectionString"
].ConnectionString;
using
(OracleConnection con =
new
OracleConnection(constr))
{
using
(OracleCommand cmd =
new
OracleCommand(query, con))
{
List<senders_list> customers =
new
List<senders_list>();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
OracleDataAdapter da =
new
OracleDataAdapter(cmd);
DataTable dt =
new
DataTable();
da.Fill(dt);
if
(dt.Rows.Count>0) {
for
(
int
i=0;i<dt.Rows.Count;i++) {
customers.Add(
new
senders_list
{
c_no = dt.Rows[i][
"c_no"
].ToString(),
c_name = dt.Rows[i][
"c_name"
].ToString()
});
}
}
return
customers; // i have created breakpoint here and it return the data fine
}
}
}
and this is the class :
public
class
senders_list
{
public
string c_no { get; set; }
public
string c_name { get; set; }
}
and im calling the ajax request from test.aspx
this is the test.aspx ,ajax call
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeBehind=
"test.aspx.cs"
Inherits=
"WEBDBIRAQI.test1"
%>
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<script type=
"text/javascript"
src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"
></script>
<script type=
"text/javascript"
>
(document).ready(function () {
$.ajax({
type:
"POST"
,
contentType:
"application/json; charset=utf-8"
,
url:
"remin.aspx/GetCustomers"
,
data:
"{}"
,
dataType:
"json"
,
success: function (Result) {
Result = Result.d;
$.each(Result, function (key, value) {
$(
"#ss_list"
).append($(
"<option></option>"
).val
(value.C_NO).html(value.C_NAME));
});
},
error: function (Result) {
alert(
"Error"
);
}
});
});
</script>
<title></title>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<div>
<asp:dropdownlist id=
"ss_list"
runat=
"server"
></asp:dropdownlist>
</div>
</form>
</body>
</html>
when i run the form it shows only the dropdownlist but with no data inside !
im sure that the problem is with my ajax call Code ,because i have created a break point in the web method and it returned the data fine !
i need help please !
Reply
Answers (
6
)
How to restore Nuget Packages in Devazure ?
Unable to install package from package manager console