473,395 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

FilterExpression and the SQLDataSource Control- returns ALL values

1
Hi,

I have a SQLDatasource control on a web page. It is the datasource for a gridview control.


At the moment i have in the contractID and duration text property the symbol '%', however If I make the TextBox empty or remove the % from the contractID and duration Textbox it returns all the names in the database when i first run the script.

How do I get the gridview to be blank when i first run the script without having to use the % in the Textboxes?

MANY THANKS!





Expand|Select|Wrap|Line Numbers
  1. <form id="form1" runat="server"> 
  2. <div>
  3. </div> 
  4. <br /> 
  5.  
  6. <asp:TextBox ID="contractID" runat="server">%</asp:TextBox> 
  7. <asp:TextBox ID="duration" runat="server">%</asp:TextBox> 
  8. <asp:Button ID="Button1" runat="server" Text="Button" /> 
  9.  
  10. <br /> 
  11.  
  12. <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="contractID"> 
  13. <Columns> 
  14.   <asp:BoundField DataField="contractID" HeaderText="contractID" ReadOnly="True" SortExpression="contractID" /> 
  15.   <asp:BoundField DataField="duration" HeaderText="duration" SortExpression="duration" /> 
  16.   <asp:BoundField DataField="noOfHourse" HeaderText="noOfHourse" SortExpression="noOfHourse" /> 
  17. </Columns>
  18. </asp:GridView> 
  19.  
  20. <br /> 
  21.  
  22. <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Contract]" FilterExpression="contractID LIKE '{0}%' AND duration LIKE '{1}%'" 
  23. EnableCaching="true" DataSourceMode="DataSet"> 
  24.   <FilterParameters> 
  25.     <asp:ControlParameter ControlID="contractID" DefaultValue="%" Name="contractID" ConvertEmptyStringToNull="false" /> 
  26.     <asp:ControlParameter ControlID="duration" DefaultValue="%" Name="duration" ConvertEmptyStringToNull="false" /> 
  27.  
  28.   </FilterParameters> 
  29. </asp:SqlDataSource>
Mar 28 '10 #1
1 3858
Frinavale
9,735 Expert Mod 8TB
Have you tried removing the "%" from the DefaultValue fields?
The "%" character is a wildcard character that matches any string with zero or more characters. It will return everything.

-Frinny
Mar 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Henry Habermacher [MVP Access] | last post by:
Environment: VS2005, ASP.Net 2.0, SQLServer 2000, VB.Net, IIS6 I use a GridView Control which is based on a SQLDataSource. The datasource is based on a Select statement and is filtered by the...
2
by: DummyDumb | last post by:
Hi, I've got a Gridview utilizing a filterexpression: <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OnDeleted="ItemDeleted" EnableCaching="true"...
0
by: wubin_98 | last post by:
When I set a SqlDataSource1.FilterExpression value to " Partnumber LIKE '87-2055-___'" , SqlDataSource return empty. But I can get correct result in SQL query by including above expression. I...
9
by: Dan Sikorsky | last post by:
When I hit the Test Query button in the SqlDataSource design, all the rows come back. But when I run the website, without any changes, in the IDE, the GridView tied to the SqlDataSoure is empty. ...
5
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason,...
4
by: David | last post by:
I cannot get my aspx page (ASP.Net 2.0) to remove the FilterExpression on a SqlDataSource. Can someone tell me what I am doing wrong? Below is the SelectCommand: <asp:SqlDataSource...
0
by: lewis | last post by:
I am having an issue with the paging functionality in the gridview I have a gridview that is setup to read from a sqldatasource. The page is a search screen, when the search button is clicked i...
1
by: Corey B | last post by:
I have a page with a DetailsView control and a SQLDataSource control. The SQLDataSource control is connected to an Access database. Everything works fine. Now I want to change the back end...
1
by: jobs | last post by:
Cannot find column . Am I missing something here... SelectCommand="SELECT , , , refid FROM " FilterExpression="phone_nbr like @phone_nbr + '%'"
3
by: Curt | last post by:
I have a gridview object with a sqldatasource as its sourceid. Everything was going so well until I came across this problem. My SELECTCOMMAND for my sqldatasource is: select...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.