27 Aug 2013

How to getting Data through web Services with jquery in asp.net c#.

In Html


<div id="div_id"></div>


In Jquery code  JqueryDatabind.js


$.fn.DataBind = function () {    
    var data = "{}";
    var url = "Testing.aspx/get_data";

    $(this).AjaxPOST(url, data, function (d) {
        if (typeof (d[0]) !== 'undefined') {
                $('#div_id').append(d[0].id.toString());
        }
    });
}


In Web Services Code

 public class DataId

 {

     public string id;
 }

[WebMethod]
public List<DataIdget_data()
{
  List<DataId> dataid= new List<DataId>();
  string query = "";
  try
  {
    // pass your Sql  connectionstring  Web.config
   SqlConnection con = new SqlConnection(Pass Your         ConnectionString );
   con.Open();
   query = "select dataid From YourTableName";
   SqlDataAdapter da = new SqlDataAdapter(query, con);
   DataSet ds = new DataSet();
   da.Fill(ds);
   

if(ds.Tables[0].Rows.Count>0)
   {
       DataListId data_list = new DataListId();

       data_list.id= ds.Tables[0].Rows[0]["dataid"].ToString();
       dataid.Add(data_list);
   }
   con.Close();
 }
 catch (Exception ex)
 {
 }
 return dataid;
}

No comments:

Post a Comment

How to Create WEBSITE DESIGN

Way2finder Technologies is a web design studio that offers corporate web design and custom web design. Our website designers offer cheap w...