Hello Everyone,
I have a requirement to fill the FormView, DataLIst using jquery.ajax
I have 2 ways to do it
1) When I do not receive any data in jquery.ajax but this leads to an error because when the focus reaches to the line -- GridView1.DataSource = ds;
This shows an error "Object Reference not set to an instance of object"
I have checked in debug mode data set object
ds is fill with data.
Error occurs only when this assigns to DataSource
2) And 2nd option is if i receive the data set data in terms of arraylist or array then how will i populate my Formview.
Because I'm using
< %#Eval('')%>
Please guide me...
<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.DataBind();
ds.Clear();
}
Thanks