首先抱歉我的英语不好。 问题是:
我希望得到2行"日期表"在ajax成功功能 这是脚本:
function SearchNamePriceProducts() {
$.ajax({
type: "POST",
url: "page.aspx/GetProduct",
data: '{ id : "' + $("#<%=txt_number_product.ClientID%>")[0].value + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccessProduct,
failure: function (response) {
alert(response.d);
}
});
};
function OnSuccessProduct(response) {
var rdata = $.parseJSON(response.d) ;
//do something like
$('#<%=txt_name_product.ClientID %>').val(rdata[0].value);
$('#<%=txtPrice.ClientID %>').val(rdata[0].value);
我做的是。在getProduct函数中按产品ID搜索。名称和价格在&#34; Datatable&#34;。
上返回c#代码是:
public static string GetProduct(string id)
{
int nro = int.Parse(id);
String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
String strQuery = "select Name, Price from Products where Id_Products=@ID";
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@ID", id);
cmd.CommandText = strQuery;
cmd.Connection = con;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "Result");
con.Close();
DataTable dt= ds.Tables["Result"];
return JsonConvert.SerializeObject(dt);
}
}
}