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
No response BIND Data to gridview using jquery
Sep 28 2018 3:20 AM
Pls help why no response BIND Data to gridview using jquery as below:-
1) WebForm6.aspx
<script type=
"text/javascript"
> src=
"http://code.jquery.com/jquery-1.11.1.min.js"
</script>
<script type=
"text/javascript"
>
$(document).ready(
function
() {
BindGridView();
});
function
BindGridView() {
$.ajax({
type:
"POST"
,
url:
"WebForm6.aspx/GetData"
,
contentType:
"application/json;charset=utf-8"
,
data: {},
dataType:
"json"
,
success:
function
(data) {
$(
"#grdDemo"
).empty();
if
(data.d.length > 0) {
$(
"#grdDemo"
).append(
"<tr><th>Username</th><th>Firstname</th></tr>"
);
//<th>Lastname</th><th>EmailID</th>
for
(
var
i = 0; i < data.d.length; i++) {
$(
"#grdDemo"
).append(
"<tr><td>"
+
data.d[i].Firstname +
"</td> <td>"
+
data.d[i].Lastname +
"</td></tr>"
);
}
}
},
error:
function
(result) {
alert(
"Error login"
);
}
});
}
</script>
2) WebForm6.aspx.cs
protected
void
Page_Load(
object
sender, EventArgs e)
{
BindDummyItem();
}
public
void
BindDummyItem()
{
DataTable dtGetData =
new
DataTable();
dtGetData.Columns.Add(
"Username"
);
dtGetData.Columns.Add(
"Firstname"
);
//dtGetData.Columns.Add("Lastname");
//dtGetData.Columns.Add("EmailID");
dtGetData.Rows.Add();
grdDemo.DataSource = dtGetData;
grdDemo.DataBind();
}
[WebMethod]
public
static
DetailsClass[] GetData()
//GetData function
{
List<DetailsClass> Detail =
new
List<DetailsClass>();
string
SelectString =
"SELECT Username,Firstname FROM TABLE"
;
OracleConnection cn =
new
OracleConnection();
cn.ConnectionString =
"Data Source=(DESCRIPTION ="
+
"(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xxx.xxx.xxx)(PORT=xxx)))"
+
"(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xxxxxx)));"
+
"User Id=xxx;Password=xxxxxx;"
;
OracleCommand cmd =
new
OracleCommand(SelectString, cn);
cn.Open();
OracleDataAdapter da =
new
OracleDataAdapter(cmd);
DataTable dtGetData =
new
DataTable();
da.Fill(dtGetData);
foreach
(DataRow dtRow
in
dtGetData.Rows)
{
DetailsClass DataObj =
new
DetailsClass();
DataObj.Username = dtRow[
"Username"
].ToString();
DataObj.Firstname = dtRow[
"Firstname"
].ToString();
Detail.Add(DataObj);
}
return
Detail.ToArray();
}
public
class
DetailsClass
//Class for binding data
{
public
string
Username {
get
;
set
; }
public
string
Firstname {
get
;
set
; }
}
Attachment:
SOURCECODE.zip
Reply
Answers (
7
)
Telerik popup not working
Pls help to check why bind data to gridview no data reponse