How to bind mongodb search result to asp.net C# gridview -


i having trouble binding mongodb search result asp.net c# gridview. whenever run program, throws nullreferenceexception: "object reference not set instance of object." after debugging, found gridview id (gridview1) null. however, have no idea why gridview1 null. appreciated.

here markup page:

<asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" backcolor="white" gridlines="both" bordercolor="#d8d8d8"      borderwidth="1px" cellpadding="4" forecolor="black" allowpaging="true" pagersettings-position="topandbottom" allowsorting="true"     datakeynames="_id" height="50px" borderstyle="none" pagesize="50" font-size="8pt" cssclass="sp_datalabel" width="99%"      onpageindexchanging="gv_pageindexchanging" onrowdatabound="gv_rowdatabound" onrowdeleting="gv_rowdeleting" onrowediting="gv_rowediting" onrowupdating="gv_rowupdating" onrowcancelingedit="gv_rowcancelingedit">         <footerstyle backcolor="#cccc99" />         <columns>                    <asp:commandfield showeditbutton="true"></asp:commandfield>                  <asp:commandfield showdeletebutton="true"></asp:commandfield>                         <asp:boundfield readonly="true" insertvisible="false" datafield="_id" headertext="id" itemstyle-width="30" />             <asp:boundfield sortexpression="isbn" datafield="isbn" headertext="isbn" itemstyle-width="150" />             <asp:boundfield sortexpression="title" datafield="title" headertext="title" itemstyle-width="150" />                 <asp:boundfield sortexpression="author" datafield="author" headertext="author" itemstyle-width="150" />                     <asp:boundfield sortexpression="publisher" datafield="publisher" headertext="publication date" itemstyle-width="150" />                <asp:boundfield sortexpression="description" datafield="description" headertext="description" itemstyle-width="150" />                                                                            </columns>           <selectedrowstyle forecolor="#ccff99" font-bold="true"              backcolor="#009999"></selectedrowstyle>         <rowstyle forecolor="#003399" backcolor="white"></rowstyle>          <pagertemplate>                             <table style="width:100%">                 <tr>                 <td style="white-space:nowrap;text-align:center">                 <div id="pager">                 <asp:imagebutton imagealign="absbottom" id="imgfirst" runat="server" commandargument="first" commandname="page" onclientclick="pageindexchanged();" imageurl="images/datacontainer_movefirsths.png" />                 <asp:imagebutton imagealign="absbottom" id="imgprevious" runat="server" commandargument="prev" commandname="page" onclientclick="pageindexchanged();" imageurl="images/datacontainer_moveprevioushs.png" />                 <asp:label id="lblpagelabel" runat="server" text="page" font-names="arial" font-size="7pt"></asp:label>                 <asp:dropdownlist id="ddlpageselector" font-names="arial" font-size="8pt" runat="server"></asp:dropdownlist>                                                     <asp:imagebutton imagealign="absbottom" id="imgnext" runat="server" commandargument="next" commandname="page" onclientclick="pageindexchanged();" imageurl="images/datacontainer_movenexths.png" />                 <asp:imagebutton imagealign="absbottom" id="imglast" runat="server" commandargument="last" commandname="page" onclientclick="pageindexchanged();" imageurl="images/datacontainer_movelasths.png" />                                                        </div>                           </td>                  </tr>                 </table>           </pagertemplate>          <pagerstyle backcolor="#f7f7de" forecolor="black" horizontalalign="right" />         <headerstyle forecolor="white" cssclass="sp_datalabel_header" font-bold="true" />         <emptydatatemplate>             &nbsp;         </emptydatatemplate>        <rowstyle font-size="12pt" backcolor="#ebf3ff" font-names="verdana" />        <alternatingrowstyle backcolor="white" font-size="12pt" font-names="verdana" />        <editrowstyle font-size="medium" />        <emptydatarowstyle font-size="medium" />     </asp:gridview> 

here code behind page:

 public async void searchbook(string title)  {         imongodatabase mdb = mongodbconnectionmanager.connecttomongodb();          var collection = mdb.getcollection<book>("book");          var builder = builders<book>.filter;         var filter = builders<book>.filter.eq("title", title);                                 var sort = builders<book>.sort.ascending("title");                      var result = await collection.find(filter).tolistasync();          gridview1.datasource = result;         gridview1.databind();          server.transfer("searchresult.aspx", true);                 }        } 


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -