我需要使用 jquery.ajax 填充 FormView、DataLIst
我有两种方法可以做到这一点
1)当我在 jquery.ajax 中没有收到任何数据但这会导致错误,因为当焦点到达该行时 -- GridView1.DataSource = ds; 这显示错误“对象引用未设置为对象的实例”我在调试模式数据集对象 ds 中检查过数据填充。仅当 this 分配给 DataSource 时才会发生错误
2)第二个选项是如果我收到数组列表或数组的数据集数据,那么我将如何填充我的Formview。因为我正在使用<%#Eval('')%>
**HtmlCode**
<asp:FormView ID="GridView1" runat="server">
<ItemTemplate>
<div >
<%# Eval("title") %>
</div>
<table>
<tr>
<td> <%# Eval("S1") %> </td>
<td> <%# Eval("S2") %> </td>
<td> <%# Eval("S3") %> </td>
</tr>
</table>
$("#btnShow").click(function () {
var selTitle = $("#ddlEDTitle options:selected").text();
$.ajax({
type: "POST",
url: "Default.aspx/GetData",
data: "{tVal:'" + selTitle + "'}",
contentType: "application/json",
dataType: "json",
success: function () {
alert("Data Filled");
},
error: function () { alert("Error : 260"); }
});
});
string rawQuery = string.Empty;
rawQuery = "SELECT Adress from temp WHERE title='" + title + "'";
System.Data.DataSet ds = new System.Data.DataSet();
ds = c.fetchData(rawQuery);
if (ds.Tables[0].Rows.Count > 0)
{
DetailsView1.DataSource = ds;
DetailsView1.DataBind();
ds.Clear();
}
rawQuery = string.Empty;
rawQuery = "SELECT * from specification WHERE title='" + title+ "'";
ds = c.fetchData(rawQuery);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
//GridView1.DataMember = "specification";
GridView1.DataBind();
ds.Clear();
}
请用您宝贵的知识指导我。
谢谢