Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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...

HTML
<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>                                                  


JavaScript
$("#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"); }
        });
    });


C#
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();
        }


Thanks
Posted

1 solution

Not clear question please explain what is the exact problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900