如何在静态方法中绑定转发器 [英] how to binde repeater in static method

查看:55
本文介绍了如何在静态方法中绑定转发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过jquery ajax调用它的web方法.在Web方法中,我将转发器数据源绑定到pagedatasourse对象,但是当我运行程序时,如果在方法名称jquery ajax方法未使用之前不使用静态关键字webmethode不能正常工作这是正常的,因为jquery ajax仅适用于静态方法,如果使用static关键字,我会遇到此错误

i have a webmethod that call it by jquery ajax .in web method i bind repeater data source to pagedatasourse object but when i run my program if i dont use of static key word webmethode before method name jquery ajax method dose not work properly and its normal because jquery ajax only work with static method and if use static keyword i have this error

报价:

对象引用未设置为对象的实例.... System.NullReferenceException:对象引用未设置为对象的实例

Object reference not set to an instance of an object....System.NullReferenceException: Object reference not set to an instance of an object



和pagedatasourse陷入异常.我很困惑.解决方案是什么?非常感谢我的jquery函数



and pagedatasourse fall in exception.i confused.what is solution? thank you very much its my jquery function

<blockquote class="FQ"><div class="FQA">Quote:</div>$(function () {
            var x = 0;
            $('.c1').bind('click', function () {
                counter = counter + 1;
                $.ajax(
                {
         type: "POST",
            url: "WebForm1.aspx/bringdata",
      data: { counter: counter },
          contentType: "application/json; charset=utf-8",
           dataType: "json",
           async: true,
            cache: false,
              success: function (ret) {

                alert("success");
           },
           error: function (x, e) {
           alert("error ");
                 }
                   }
                );

            })
            $('.c2').bind('click', function () {

                x = x - 1;

            })

        })



及其代码behiend



and its code behiend

<blockquote class="FQ"><div class="FQA">Quote:</div>
    [WebMethod]
   public static void bringdata(int counter){
       SqlConnection con = new SqlConnection("data source=.;database=site;integrated security=true;");
       int cnt;
   string sSQL = "Select username ,average,weight,point,password ,kal, Rank() over(order by point desc) as 'ranking' from karbar order by point desc";  
SqlCommand cmd = new SqlCommand(sSQL, con);  

       SqlDataAdapter adapt = new SqlDataAdapter(cmd);
       DataSet ds = new DataSet();
       adapt.Fill(ds);
       cnt=ds.Tables[0].Rows.Count;
       PagedDataSource  pds = new PagedDataSource();
       pds.AllowPaging=true;
       pds.DataSource=ds.Tables[0].DefaultView;
       pds.PageSize=5;
       pds.CurrentPageIndex=counter;
       int vcnt=cnt/pds.PageSize;

       rptList.DataSource = pds;
       rptList.DataBind();


   }

推荐答案

( function (){ var x = 0 ;
(function () { var x = 0;


(.c1').bind(点击'功能(){ counter = counter + 1 ;
('.c1').bind('click', function () { counter = counter + 1;


.ajax( { 类型:" , 网址:" , 数据:{计数器:计数器}, contentType:" , dataType:" , 异步: true , 缓存: false , 成功:功能(ret){ alert(" ); }, 错误:函数(x,e){ alert(" ); } } ); })
.ajax( { type: "POST", url: "WebForm1.aspx/bringdata", data: { counter: counter }, contentType: "application/json; charset=utf-8", dataType: "json", async: true, cache: false, success: function (ret) { alert("success"); }, error: function (x, e) { alert("error "); } } ); })


这篇关于如何在静态方法中绑定转发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆