Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Display full data table instead of only search input
    primarykey
    data
    text
    <p>I am using VS2005 C# and SQL Server 2005.</p> <p>Currently I am able to display data using datasource from the sql statement SELECT * from table. </p> <p>Now I have implemented a search function on my table which will display search results as of user's input.</p> <p>However, I am not able to set the default display of the datatable to list all data by default or when the search textbox is empty. </p> <p>I am following this guide: <a href="http://www.asp.net/data-access/tutorials/displaying-data-with-the-objectdatasource-cs" rel="nofollow noreferrer">http://www.asp.net/data-access/tutorials/displaying-data-with-the-objectdatasource-cs</a> and I am basically stuck at the final part where he puts in an if-else statement for his datatable listng, which I have no idea where to change mine :(</p> <p>Below are the codes and screenshots:</p> <p>RPList.aspx.cs:</p> <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/MainPage.master" AutoEventWireup="true" CodeFile="RPList.aspx.cs" Inherits="SimpleDisplay" Title="Untitled Page" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server"&gt; Role: &lt;asp:TextBox ID="RPbyRoleTB" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID="RPbyRoleBtn" runat="server" Text="Show Roles &amp; Processes" /&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:&lt;connection&gt; %&gt;" SelectCommand="SELECT * FROM [RolesProcess] WHERE ([Role] = @Role)"&gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter ControlID="RPbyRoleTB" Name="Role" PropertyName="Text" Type="String" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;script language="javascript" type="text/javascript"&gt; // &lt;!CDATA[ // ]]&gt; &lt;/script&gt; &lt;asp:GridView ID="GridView1" runat="server" AllowSorting="True" DataSourceID="SqlDataSource1"&gt; &lt;/asp:GridView&gt; &lt;/asp:Content&gt; </code></pre> <p><img src="https://i.stack.imgur.com/2lTrM.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/scSAO.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/imPrC.png" alt="enter image description here"></p> <p>What do I need to do so that when my page loads or when the search box is empty, it will show the full datatable by default?</p> <hr> <p>As suggested by Politia, I have tried changing my query to SELECT [columns] FROM RolesProcess WHERE (Role = @Role) OR (LEN(@Role) = 0), however, as what I've commented, it doesn't seem to work as smoothly as i thought. Below are the screenshots.</p> <p><img src="https://i.stack.imgur.com/Kj3Gp.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/A9wAv.png" alt="enter image description here"></p> <hr> <p>Behind code for page after changing sql query:</p> <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/MainPage.master" AutoEventWireup="true" CodeFile="RPList.aspx.cs" Inherits="SimpleDisplay" Title="Untitled Page" %&gt; &lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server"&gt; &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:SODConnectionString %&gt;" SelectCommand="SELECT [columns] FROM RolesProcess WHERE (Role = @Role) OR (LEN(@Role) = 0) OR (@Role IS NULL)"&gt; &lt;SelectParameters&gt; &lt;asp:ControlParameter ControlID="TextBox1" Name="Role" PropertyName="Text" Type="String" DefaultValue="" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID="Button1" runat="server" Text="Button" /&gt; &lt;script language="javascript" type="text/javascript"&gt; // &lt;!CDATA[ // ]]&gt; &lt;/script&gt; &lt;asp:GridView ID="GridView1" runat="server" AllowSorting="True" DataSourceID="SqlDataSource1"&gt; &lt;/asp:GridView&gt; &lt;/asp:Content&gt; </code></pre> <p>The queries all works during configuration. Now when I load my page, the tables doesn't appear, and even if I search for 'blank' values, the table does not show any data as well.</p> <p>Image of page when it loads, and even if I clicked on the button, nothing shows out. <img src="https://i.stack.imgur.com/ABhw2.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload