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
Chriz L
NA
220
51.1k
Jquery how to pass GridView as a parameter to a WebMethod
Sep 15 2016 2:16 AM
Hello,
I'm trying to pass a GridView as parameter from Javascript to a WebMethod. Here's my code:
<script src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"
type=
"text/javascript"
></script>
<script type =
"text/javascript"
>
function bindGrid() {
var pageurl =
'<%=ResolveUrl("Default.aspx/bindGrid1") %>'
;
var gv = $(
"#<%=gvDisplay.ClientID%>"
).val();
var idno = $(
"#<%=txtIDNO.ClientID%>"
).val();
var name = $(
"#<%=txtName.ClientID%>"
).val();
var tel = $(
"#<%=txtTel.ClientID%>"
).val();
var parameter={
"gv"
:gv,
"idno"
:idno,
"name"
:name,
"tel"
:tel}
$.ajax({
type:
"POST"
,
url: pageurl,
data: JSON.stringify(parameter),
contentType:
"application/json; charset=utf-8"
,
dataType:
"json"
,
success: OnSuccess,
failure: function(response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
</script>
and the WebMethod:
[WebMethod]
public
static
string
bindGrid1(GridView gv, String idno, String name, String tel)
{
string
message =
""
;
DataSet ds;
SqlDataAdapter SqlAda;
SqlConnection con = getConnection();
SqlCommand cmd =
new
SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText =
"sproc"
;
cmd.Parameters.Add(
"@IDNO"
, SqlDbType.VarChar).Value = idno;
cmd.Parameters.Add(
"@Name"
, SqlDbType.VarChar).Value = name;
cmd.Parameters.Add(
"@Tel"
, SqlDbType.VarChar).Value = tel;
cmd.Connection = con;
try
{
con.Open();
gv.EmptyDataText =
"No data."
;
SqlAda =
new
SqlDataAdapter(cmd);
ds =
new
DataSet();
SqlAda.Fill(ds);
gv.DataSource = ds;
gv.DataBind();
message =
"success"
;
}
catch
(Exception ex)
{
appObj.myMessageBox(ex.Message);
message =
"error"
;
}
finally
{
con.Close();
con.Dispose();
}
return
message;
}
I know I can't pass it as a string, but I can't find a way to pass it.
Any kind of help would be appreciated.
Thank you in advance.
Reply
Answers (
1
)
how to convert object to json and json to object?
how to get html value into c# page