title: how to bind dataset with gridview
body: <p>This is my code .aspx.cs page</p>
  
  <pre><code>public string makequery()
  {
      string query = string.Empty;
      if (ddlPortal2.SelectedValue == "Select" &amp;&amp; tbFrom.Text == null &amp;&amp; tbTo.Text == null &amp;&amp; ddlQuery.SelectedValue == "Select")
      {
          query = "SELECT * FROM Form3 and ORDER BY CONVERT(VARCHAR(25), [Datetime], 101) between '" + tbFrom.Text + "' and '" + tbTo.Text + "' DESC";
          return query;
      }
      else if(ddlPortal2.SelectedItem.Text!="Select" &amp;&amp; tbFrom.Text!=null &amp;&amp; tbTo.Text!=null &amp;&amp; ddlQuery.SelectedItem.Text=="Select")
      {
          query = "Select * from Form3 where Portal='" + ddlPortal2.SelectedValue + "' and ORDER BY CONVERT(VARCHAR(25), [Datetime], 101) between '" + tbFrom.Text + "' and '" + tbTo.Text + "' DESC";
          return query;
      }
      else if (ddlPortal2.SelectedItem.Text != "Select" &amp;&amp; tbFrom.Text == null &amp;&amp; tbTo.Text == null &amp;&amp; ddlQuery.SelectedItem.Text != "Select")
      {
          query = "Select * from Form3 where Portal='" + ddlPortal2.SelectedValue + "' and ORDER BY CONVERT(VARCHAR(25), [Datetime], 101) between '" + tbFrom.Text + "' and '" + tbTo.Text + "' DESC";
          return query;
      }
      return null;
  }
  public void GridViewBind()
  {
      string query = makequery();
      DataSet ds = new DataSet();
      if (ds != null)
      {
          if (ds.Tables[0].Rows.Count != 0)
          {
              GridView1.DataSource = ds;
              GridView1.DataBind();
          }
          else
          {
              GridView1.DataSource = null;
              GridView1.DataBind();
          }
      }
  }
  protected void btnSearch_Click(object sender, EventArgs e)
  {
      this.GridViewBind();
  }
  </code></pre>
  
  <p>}
  .aspx page code:</p>
  
  <pre><code>&lt;div id="Portal" runat="server"&gt;
  &lt;asp:Label ID="lblPortal" runat="server" Text="Select Portal"/&gt;
      &lt;asp:DropDownList ID="ddlPortal2" runat="server" AutoPostBack="True"&gt;
          &lt;asp:ListItem&gt;Select&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;TRAVELONG&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;ONETRAVEL&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;.UK-BSP&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;.CV-YYZ&lt;/asp:ListItem&gt;
          &lt;asp:ListItem&gt;.CV-YVR&lt;/asp:ListItem&gt;
      &lt;/asp:DropDownList&gt;
     &lt;asp:Label ID="lbFrom" Text="From" runat="server" /&gt;
  &lt;asp:TextBox ID="tbFrom" runat="server" /&gt;
   &lt;asp:RequiredFieldValidator ID="rfvFrom" runat="server" ControlToValidate="tbFrom" ErrorMessage="Enter Valid Date"&gt;*&lt;/asp:RequiredFieldValidator&gt;
         &lt;asp:Label ID="lblto" Text="To" runat="server" /&gt;
  &lt;asp:TextBox ID="tbTo" runat="server" /&gt;
          &lt;asp:RequiredFieldValidator ID="rfvTo" runat="server" ControlToValidate="tbTo" 
          ErrorMessage="Enter To date"&gt;*&lt;/asp:RequiredFieldValidator&gt;
           &lt;asp:DropDownList ID="ddlQuery" runat="server" Width="87px"&gt;
             &lt;asp:ListItem&gt;All&lt;/asp:ListItem&gt;
             &lt;asp:ListItem Value="Query "&gt;Query&lt;/asp:ListItem&gt;
             &lt;asp:ListItem&gt;Non Query&lt;/asp:ListItem&gt;
      &lt;/asp:DropDownList&gt;
  &lt;asp:Button ID="btnSearch" runat="server" Text="Search" 
      onclick="btnSearch_Click" ValidationGroup="1"/&gt;&lt;br /&gt;
  
          &lt;br /&gt;           
      &lt;asp:ValidationSummary ID="ValidationSummary1" runat="server" /&gt;
      &lt;/div&gt;
  &lt;div id="Main" runat="server"&gt;
  &lt;asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" 
          GridLines="None" onrowcommand="GridView1_RowCommand" 
          AutoGenerateColumns="False"&gt;
          &lt;Columns&gt;
         &lt;asp:TemplateField HeaderText="Select"&gt;
              &lt;itemtemplate&gt;
              &lt;asp:LinkButton CommandName="cmdBind"  runat="server" Text='&lt;%#Eval("ID")%&gt;' ID="ID" ToolTip='&lt;%#Eval("ID")%&gt;'&gt;LinkButton                &lt;/asp:LinkButton&gt;                                                                   
              &lt;/itemtemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField HeaderText="Date"&gt;
              &lt;ItemTemplate&gt;
                      &lt;asp:Label ID="lblDateTime" runat="server" Text='&lt;%# Eval("DateTime","{0:d}") %&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;   
              &lt;asp:BoundField DataField="Portal" HeaderText="Portal" SortExpression="Portal" ItemStyle-HorizontalAlign="Center"/&gt;
              &lt;asp:BoundField DataField="TID" HeaderText="TID" SortExpression="TID" ItemStyle-HorizontalAlign="Center"/&gt;
              &lt;asp:BoundField DataField="PNR" HeaderText="PNR" SortExpression="PNR" ItemStyle-HorizontalAlign="Center"/&gt;
              &lt;asp:BoundField DataField="TicketNumber" HeaderText="TicketNumber" SortExpression="TicketNumber" ItemStyle-HorizontalAlign="Center"/&gt;
            &lt;asp:TemplateField HeaderText="Unused Tkt Amount" SortExpression="ddlUnusedAmount" ItemStyle-HorizontalAlign="Center"&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:Label ID="lblUnusedAmount" runat="server" Text='&lt;%#Eval("UnusedTicketAmount")+ "-" + Eval("ddlUnusedAmount")%&gt;' &gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Penality" SortExpression="ddlAirlinePenality" ItemStyle-HorizontalAlign="Center"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="lblAirlinePenality" runat="server" Text='&lt;%#Eval("AirlinePenality")+ "-" + Eval("ddlAirlinePenality")%&gt;' &gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Net Refund" SortExpression="ddlNetRefundProcess" ItemStyle-HorizontalAlign="Center"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="lblNetRefund" runat="server" Text='&lt;%#Eval("NetRefundProcess")+ "-" + Eval("ddlNetRefundProcess")%&gt;' &gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Refundable Commission"   SortExpression="ddlRefundableCommission" ItemStyle-HorizontalAlign="Center"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="lblRefundableCommission" runat="server" Text='&lt;%#Eval("RefundableCommission")+ "-" + Eval("ddlRefundableCommission")%&gt;' &gt;&lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
              &lt;asp:BoundField DataField="ESACCode" HeaderText="ESACCode" SortExpression="ESACCode" ItemStyle-HorizontalAlign="Center"/&gt;
              &lt;asp:BoundField DataField="WaiverCode" HeaderText="WaiverCode" SortExpression="WaiverCode" ItemStyle-HorizontalAlign="Center"/&gt;
              &lt;asp:BoundField DataField="RefundType" HeaderText="RefundType" SortExpression="RefundType" ItemStyle-HorizontalAlign="Center" /&gt;
               &lt;asp:BoundField DataField="Comment" HeaderText="Bart Comment" ItemStyle-HorizontalAlign="Center"/&gt; 
          &lt;asp:BoundField DataField="Query" HeaderText="ARC Verified" ItemStyle-HorizontalAlign="Center" /&gt;
      &lt;/Columns&gt;       
  </code></pre>
  
  <p>Now here I make two function one to make query and second to bind that query with <code>dataset</code> with <code>gridview</code> when I bind <code>dataset</code> Cannot find table 0.  </p>
  
  <p>what I want is when I select field and press search button I can view details in my grid according to the selected fields but I can't bind it with my <code>dataset</code>. Can you guys help me with this.</p>