我正在尝试使用Ajax jquery绑定gridview。虽然我看到数据与gridview绑定并在浏览器中显示但是在完成调试之后。填充行的所有数据都会消失。请找出问题但是在执行$(“#THistory”)之后。单击(function(){此函数调试器转到Page_Load方法 Ajax部分
<%--GridView Populate--%>
<script type="text/javascript">
$(function () {
$("#THistory").click(function () {
$.ajax({
type: "POST",
url: "TDC.aspx/GetCustomers",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
});
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var customers = xml.find("Table");
var row = $("[id*=gvCustomers] tr:last-child").clone(true);
$("[id*=gvCustomers] tr").not($("[id*=gvCustomers] tr:first-child")).remove();
$.each(customers, function () {
var customer = $(this);
$("td", row).eq(0).html($(this).find("REVISION").text());
$("td", row).eq(1).html($(this).find("P_GROUP").text());
$("[id*=gvCustomers]").append(row);
row = $("[id*=gvCustomers] tr:last-child").clone(true);
});
}
});
</script>
<%--GridView Populate--%>
的.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindDummyRow();
}
}
private void BindDummyRow()
{
DataTable dummy = new DataTable();
dummy.Columns.Add("REVISION");
dummy.Columns.Add("P_GROUP");
dummy.Rows.Add();
gvCustomers.DataSource = dummy;
gvCustomers.DataBind();
//gvCustomers.Visible = false;
}
[WebMethod]
public static string GetCustomers()
{
string query = "SELECT REVISION, P_GROUP from tdc_product1 ";
OracleCommand cmd = new OracleCommand(query);
return GetData(cmd).GetXml();
}
private static DataSet GetData(OracleCommand cmd)
{
string strConnString = ConfigurationManager.ConnectionStrings["conndbprodnew"].ConnectionString;
using (OracleConnection con = new OracleConnection(strConnString))
{
using (OracleDataAdapter sda = new OracleDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
return ds;
}
}
}
}