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
Francky Frined
NA
50
1.5k
Please help to check when loading, error persists below code
Oct 1 2018 3:21 AM
Please help to check when loading, error persists below code :-
1) Default.aspx
<script type=
"text/javascript"
src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"
></script>
<script type=
"text/javascript"
>
$(document).ready(
function
() {
$.ajax({
type:
"POST"
,
contentType:
"application/json; charset=utf-8"
,
url:
"Default.aspx/BindDatatable"
,
data:
"{}"
,
dataType:
"json"
,
success:
function
(data) {
for
(
var
i = 0; i < data.d.length; i++) {
$(
"#gvDetails"
).append(
"<tr><td>"
+ data.d[i].UserId +
"</td><td>"
+ data.d[i].UserName +
"</td><td>"
+ data.d[i].Location +
"</td></tr>"
);
}
},
error:
function
(result) {
alert(
"Error"
);
}
});
});
</script>
<style type=
"text/css"
>
table,th,td
{
border:1px solid black;
border-collapse:collapse;
}
</style>
<form id=
"form1"
runat=
"server"
>
<asp:GridView ID=
"gvDetails"
runat=
"server"
>
<HeaderStyle BackColor=
"#DC5807"
Font-Bold=
"true"
ForeColor=
"White"
/>
</asp:GridView>
</form>
2) Default.aspx code behind
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
BindColumnToGridview();
}
}
private
void
BindColumnToGridview()
{
DataTable dt =
new
DataTable();
dt.Columns.Add(
"UserId"
);
dt.Columns.Add(
"UserName"
);
dt.Rows.Add();
gvDetails.DataSource = dt;
gvDetails.DataBind();
gvDetails.Rows[0].Visible =
false
;
}
[System.Web.Services.WebMethod]
public
static
UserDetails[] BindDatatable()
{
DataTable dt =
new
DataTable();
List<UserDetails> details =
new
List<UserDetails>();
using
(OracleConnection con =
new
OracleConnection(
"Data Source=(DESCRIPTION ="
+
"(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xxx.xxx.xxx)(PORT=xxxx)))"
+
"(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xxxxxx)));"
+
"User Id=xxxx;Password=xxxxxxxx;"
))
{
using
(OracleCommand cmd =
new
OracleCommand(
"SELECT UserId,UserName FROM table"
, con))
{
con.Open();
OracleDataAdapter da =
new
OracleDataAdapter(cmd);
da.Fill(dt);
foreach
(DataRow dtrow
in
dt.Rows)
{
UserDetails user =
new
UserDetails();
user.UserId = dtrow[
"UserId"
].ToString();
user.UserName = dtrow[
"UserName"
].ToString();
details.Add(user);
}
}
}
return
details.ToArray();
}
public
class
UserDetails
{
public
string
UserId {
get
;
set
; }
public
string
UserName {
get
;
set
; }
}
Attachment:
Checking.zip
Reply
Answers (
3
)
Pls help to check why bind data to gridview no data reponse
Success Function Return Error