2 fengdawobaoshu FengDaWoBaoShu 于 2015.06.15 19:32 提问

JQUERY ajax提交数据到后台,进行数据库查询,然后重新绑定GridView.

我在前台放了一个input,type=button,点击后触发下面的ajax提交数据到后台。后台处理后对一个GridView进行数据绑定。
前台代码如下:

 params = JSON.stringify(obj);
            $.ajax({
                type: "Post",
                url: "/aspx_consumption/Consumption_Home.aspx/AdvanceSearch",
                data: params,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    alert(date);
                },
                error: function (err) {
                    alert(err);
                }
            });

后台也没问题:

  [WebMethod]
        public static DataSet AdvanceSearch(string Factory_Style_No, string Customer_Style_No, string Style_Type, string Writer, string Start, string End, string pageSize, string pageIndex)
        {
            DataSet ds = new DataSet();
            string connStr = @System.Configuration.ConfigurationManager.ConnectionStrings["Sample_Room_ProgressConnectionString"].ToString();
            SqlConnection conn = new SqlConnection(connStr);
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.Text;
            //cmd.CommandText = "SELECT Consumption_ID,Consumption_Factory_Style_No,Customer_Style_No,Quantity,Writer,Sample_Type,Write_Date,Confirmation,Approval FROM [Sample_Room_Progress].[dbo].[Consumption] where Factory_Style_No like '%'+@Factory_Style_No+'%' AND Customer_Style_No like '%'+@Customer_Style_No+'%' AND Sample_Type like '%'+@Sample_Type+'%' AND Writer like '%'+@Writer+'%' BETWEEN Write_Date >=@Start AND Write_Date<=@End order by Write_Date DESC";
            cmd.CommandText = "SELECT Consumption_ID,Consumption_Factory_Style_No,Customer_Style_No,Quantity,Writer,Sample_Type,Write_Date,Confirmation,Approval FROM [Sample_Room_Progress].[dbo].[Consumption] where Factory_Style_No like '%'+@Factory_Style_No+'%' AND Customer_Style_No like '%'+@Customer_Style_No+'%' AND Sample_Type like '%'+@Sample_Type+'%' AND Writer like '%'+@Writer+'%' AND Write_Date between @Start and @End  order by Write_Date DESC";
            cmd.Parameters.Add("@Factory_Style_No", SqlDbType.NVarChar);
            cmd.Parameters["@Factory_Style_No"].Value = Factory_Style_No;
            cmd.Parameters.Add("@Customer_Style_No", SqlDbType.NVarChar);
            cmd.Parameters["@Customer_Style_No"].Value = Customer_Style_No;
            cmd.Parameters.Add("@Sample_Type", SqlDbType.NVarChar);
            cmd.Parameters["@Sample_Type"].Value = Style_Type;
            cmd.Parameters.Add("@Writer", SqlDbType.NVarChar);
            cmd.Parameters["@Writer"].Value =Writer;
            cmd.Parameters.Add("@Start", SqlDbType.DateTime);
            if (Start == "")
            {
                cmd.Parameters["@Start"].Value = DBNull.Value;
            }
            else
            {
                cmd.Parameters["@Start"].Value = Start;
            }

            cmd.Parameters.Add("@End", SqlDbType.DateTime);
            if (End == "")
            {
                cmd.Parameters["@End"].Value = DBNull.Value;
            }
            else
            {
                cmd.Parameters["@End"].Value = End;
            }           
            SqlDataAdapter ad = new SqlDataAdapter();
            ad.SelectCommand = cmd;
            int indexNum = Convert.ToInt32(pageIndex);
            int SizeNum = Convert.ToInt32(pageSize);
            ad.Fill(ds, indexNum, SizeNum, "Consumption");
            return ds;
        }

但是用Jquery ajax提交数据,后台必需要静态方法似乎没法操作ASP.NET控件。有什么办法可以解决?难道我只能用asp.net控件吗?

4个回答

bdmh
bdmh   Ds   Rxr 2015.06.15 21:09

其实前后台是可以互调的,你可以通过调用后台方法去控制,另外现在有很多第三方的js表格组件,用起来比asp.net的表格组件好用多了

guwei4037
guwei4037   Ds   Rxr 2015.06.15 21:10
cuiwei1026522829
cuiwei1026522829   Ds   Rxr 2015.06.15 23:51
showbo
showbo   Ds   Rxr 2015.10.31 10:45

需要使用前台的js更新dg客户端生成的html代码,ajax请求的的aspx和当前页面显示的不是一样的。

可以使用第三方的ui,如easyUI,或者使用微软自带的updatepanel

Csdn user default icon
上传中...
上传图片
插入图片