0

i have following code how to bind grid using Java script i want to call aspx.cs code and retrieve data and bind with grid without post-back please help me. i am new asp.net please help me. i have call this method but not success

       <script type='text/javascript'>


                          $(document).ready(function () {

                              bindjs();

                          })

                          function bindjs() {

                              PageMethods.BindGrid(Success, Failure);
                          }
                          function Success(result) {
                              alert(result);
                          }
                          function Failure(error) {
                              alert(error);
                          }
</script>

and my Asp.cs method is

    [WebMethod]
    public static  DataTable BindGrid()
    {

        con = new SqlConnection(constr);
        da = new SqlDataAdapter("select tblStudent.student_id,tblStudent.student_name,tblStudent.father_name," +
            "tblStudent.Cell,tblStudent.parents_cell,tblStudent.admission_date,tblclassinfo.class_name,address_student" +
            " from tblStudent  inner join tblclassinfo on tblStudent.class_id =  tblclassinfo.class_id", con);



        DataTable dt = new DataTable();
        da.Fill(dt);
        return dt;

    }
5
  • are you using url: "localhost:54913/pages/studentinformation.aspx" like wcf for you? Commented May 17, 2016 at 20:56
  • no its webform page i want call method asp.cs method Commented May 17, 2016 at 20:58
  • 1
    ahh ok, so you dont have call any post on your javascript , only you have set public your method and access from javascript, or trt this c-sharpcorner.com/UploadFile/rohatash/… Commented May 17, 2016 at 21:02
  • how to bind grid with javascript code Commented May 17, 2016 at 21:34
  • the best mode is using ajax wcf enabled with c# , in this case once defined your webservice and method you can access via javascript and with jquery or custom dom render your grid c-sharpcorner.com/UploadFile/0c1bb2/ajax-enabled-wcf-service Commented May 17, 2016 at 21:43

1 Answer 1

1

You will have to change the cs class to be inherited from

public class Service1 : System.Web.Services.WebService

And then you method as follows

<WebMethod()> _
void BindGrid(string bookingInformation) {

    //your code here

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.