while configuration sqldatasouce1 IN ASP.NET i used sql statement where sql statement is working well in Test Query THE statement is as follows
SELECT
Name, Gender, Cast, Qualification, Occupation, Country, Age
FROM
Registration
WHERE
(Gender = @gender OR @gender IS NULL)
AND (Cast = @cast OR @cast IS NULL)
AND (Country = @country OR @country IS NULL)
AND (Age >= @Age OR @Age IS NULL)
AND (Age <= @Age2 OR @Age2 IS NULL)
in my design view I have 1 dropdownbox for gender 1 for cast 1 textbox to select age from another textbox to but it’s not working when I run the design. It’s working only when I fill all values for parameter.
here is my asp source code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="PatnerSearch.aspx.vb"
Inherits="PatnerSearch" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 90px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 122px">
<table class="style1">
<tr>
<td class="style2">
Gender</td>
<td>
<asp:DropDownList ID="ddgender" runat="server" DefaultValue=" " AutoPostBack="True">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
<asp:ListItem>Female</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style2">
Cast</td>
<td>
<asp:DropDownList ID="ddcast" runat="server" DefaultValue=" " AutoPostBack="True">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Sunni</asp:ListItem>
<asp:ListItem>Shai</asp:ListItem>
<asp:ListItem>Madhvi</asp:ListItem>
<asp:ListItem>Mamens</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style2">
Age</td>
<td>
From:
<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
To:
<asp:TextBox ID="txtto" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Country</td>
<td>
<asp:DropDownList ID="ddcountries" runat="server" DefaultValue=" " AutoPostBack="True">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>Afghanistan</asp:ListItem>
<asp:ListItem>Akrotiri</asp:ListItem>
<asp:ListItem>Albania</asp:ListItem>
<asp:ListItem>Algeria</asp:ListItem>
<asp:ListItem>American Samoa</asp:ListItem>
<asp:ListItem>Andorra</asp:ListItem>
<asp:ListItem>Angola</asp:ListItem>
<asp:ListItem>Anguilla</asp:ListItem>
<asp:ListItem>Antarctica</asp:ListItem>
<asp:ListItem>Antigua and Barbuda</asp:ListItem>
<asp:ListItem>Argentina</asp:ListItem>
<asp:ListItem>Armenia</asp:ListItem>
<asp:ListItem>Aruba</asp:ListItem>
<asp:ListItem>Ashmore and Cartier Islands</asp:ListItem>
<asp:ListItem>Australia</asp:ListItem>
<asp:ListItem>Austria</asp:ListItem>
<asp:ListItem>Azerbaijan</asp:ListItem>
<asp:ListItem>Bahamas, The</asp:ListItem>
<asp:ListItem>Bahrain</asp:ListItem>
<asp:ListItem>Bangladesh</asp:ListItem>
<asp:ListItem>Barbados</asp:ListItem>
<asp:ListItem>Bassas da India</asp:ListItem>
<asp:ListItem>Belarus</asp:ListItem>
<asp:ListItem>Belgium</asp:ListItem>
<asp:ListItem>Belize</asp:ListItem>
<asp:ListItem>Benin</asp:ListItem>
<asp:ListItem>Bermuda</asp:ListItem>
<asp:ListItem>Bhutan</asp:ListItem>
<asp:ListItem>Bolivia</asp:ListItem>
<asp:ListItem>Bosnia and Herzegovina</asp:ListItem>
<asp:ListItem>Botswana</asp:ListItem>
<asp:ListItem>Bouvet Island</asp:ListItem>
<asp:ListItem>Brazil</asp:ListItem>
<asp:ListItem>British Indian Ocean Territory</asp:ListItem>
<asp:ListItem>British Virgin Islands</asp:ListItem>
<asp:ListItem>Brunei</asp:ListItem>
<asp:ListItem>Bulgaria</asp:ListItem>
<asp:ListItem>Burkina Faso</asp:ListItem>
<asp:ListItem>Burma</asp:ListItem>
<asp:ListItem>Burundi</asp:ListItem>
<asp:ListItem>Cambodia</asp:ListItem>
<asp:ListItem>Cameroon</asp:ListItem>
<asp:ListItem>Canada</asp:ListItem>
<asp:ListItem>Cape Verde</asp:ListItem>
<asp:ListItem>Cayman Islands</asp:ListItem>
<asp:ListItem>Central African Republic</asp:ListItem>
<asp:ListItem>Chad</asp:ListItem>
<asp:ListItem>Chile</asp:ListItem>
<asp:ListItem>China</asp:ListItem>
<asp:ListItem>Christmas Island</asp:ListItem>
<asp:ListItem>Clipperton Island</asp:ListItem>
<asp:ListItem>Cocos (Keeling) Islands</asp:ListItem>
<asp:ListItem>Colombia</asp:ListItem>
<asp:ListItem>Comoros</asp:ListItem>
<asp:ListItem>Congo, Democratic Republic of the</asp:ListItem>
<asp:ListItem>Congo, Republic of the</asp:ListItem>
<asp:ListItem>Europe</asp:ListItem>
<asp:ListItem>UK</asp:ListItem>
<asp:ListItem>USA</asp:ListItem>
<asp:ListItem>Germany</asp:ListItem>
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>Pakistan</asp:ListItem>
<asp:ListItem>Bangladesh</asp:ListItem>
<asp:ListItem>Srilanka</asp:ListItem>
<asp:ListItem>Nepal</asp:ListItem>
<asp:ListItem>China</asp:ListItem>
<asp:ListItem>Japan</asp:ListItem>
<asp:ListItem>UAE</asp:ListItem>
<asp:ListItem>KSA</asp:ListItem>
<asp:ListItem>South Africa</asp:ListItem>
<asp:ListItem>Hong Kong</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" Text="Search" />
<br />
<br />
<br />
<br />
</div>
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender"
SortExpression="Gender" />
<asp:BoundField DataField="Cast" HeaderText="Cast" SortExpression="Cast" />
<asp:BoundField DataField="Qualification" HeaderText="Qualification"
SortExpression="Qualification"></asp:BoundField>
<asp:BoundField DataField="Occupation" HeaderText="Occupation"
SortExpression="Occupation" />
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
<asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
</Columns>
</asp:GridView>
<p>
</p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Database1ConnectionString %>"
SelectCommand="SELECT Name, Gender, Cast, Qualification, Occupation, Country, Age FROM Registration WHERE (Gender = @gender OR @gender IS NULL) AND (Cast = @cast OR @cast IS NULL) AND (Country = @country OR @country IS NULL) AND (Age >= @Age OR @Age IS NULL) AND (Age <= @Age2 OR @Age2 IS NULL)">
<SelectParameters>
<asp:ControlParameter ControlID="ddgender" Name="Gender"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddcast" Name="Cast"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddcountries" Name="country"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="txtfrom" Name="Age" PropertyName="Text" />
<asp:ControlParameter ControlID="txtto" Name="Age2" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
My button event is as below
Partial Class PatnerSearch
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
Edit: sorry, I first misunderstood your problem.
The solution to your problem, however, is simple.
Just set CancelSelectOnNullParameter on your SqlDataSource to False