我需要使用jquery.ajax来填充FormView,DataLIst 我有两种方法可以做到这一点
1)当我在jquery.ajax中没有收到任何数据但这会导致错误,因为当焦点到达该行时 - GridView1.DataSource = ds; 这显示错误"对象引用未设置为对象的实例" 我已经在调试模式下检查了数据集对象ds是否填充了数据。 仅当此分配给DataSource
时才会发生错误2)第二个选项是,如果我收到arraylist或array的数据集数据,那么我将如何填充我的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();
}
请指导我的宝贵知识 谢谢