2016-05-17 59 views
0

我有如下代碼如何使用Java腳本綁定網格我想調用aspx.cs代碼並檢索數據並綁定與網格沒有回發請幫助我。我是新的asp.net請幫助我。我有調用此方法,但沒有成功如何從asp.cs方法獲取JavaScript中的數據

 <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>

和我Asp.cs方法是

[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; 

    } 
+0

您是否使用url:「http:// localhost:54913/pages/studentinformation.aspx」就像wc​​f for you? –

+0

沒有它的網頁形式的頁面我想呼叫方法asp.cs方法 –

+1

啊好的,所以你沒有調用你的JavaScript的任何職位,只有你已經公開你的方法和訪問從JavaScript,或trt這個http://www.c -sharpcorner.com/UploadFile/rohatash/calling-server-side-function-from-javascript-in-Asp-Net/ –

回答

1

你將不得不改變CS類從

繼承
public class Service1 : System.Web.Services.WebService 

然後你的方法如下

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

    //your code here 

} 
+0

我編輯我的文章不成功您的回答 –

+0

如何用javascript代碼綁定網格 –

相關問題