Here is my entire web form so you can see what I have done. I want to be able to put the value of generatePassword(6) into the: InsertCommand="INSERT INTO utcasesTest(created_by_user_id, status_id, criticality_id, project_id, case_num, ... field in my db table.
<%# Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
'Our Function generatePassword accepts one parameter 'passwordLength'
'passwordLength will obviously determine the password length.
'The aplhanumeric character set is assigned to the variable sDefaultChars
Function generatePassword(passwordLength)
'Declare variables
Dim sDefaultChars
Dim iCounter
Dim sMyPassword
Dim iPickedChar
Dim iDefaultCharactersLength
Dim iPasswordLength
'Initialize variables
sDefaultChars = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789"
iPasswordLength = passwordLength
iDefaultCharactersLength = Len(sDefaultChars)
Randomize() 'initialize the random number generator
'Loop for the number of characters password is to have
For iCounter = 1 To iPasswordLength
'Next pick a number from 1 to length of character set
iPickedChar = Int((iDefaultCharactersLength * Rnd) + 1)
'Next pick a character from the character set using the random number iPickedChar
'and Mid function
sMyPassword = sMyPassword & Mid(sDefaultChars, iPickedChar, 1)
Next
generatePassword = sMyPassword
End Function
</script>
<script runat="server" type="text/vb">
Sub FormView1_Item_Inserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs)
Response.Redirect("ThankYou.asp")
End Sub
Protected Sub FormView1_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.FormViewPageEventArgs)
End Sub
Protected Sub SqlDataSource1_Selecting(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<!-- Input Form-->
<form id="form1" runat="server" method="post">
<div>
<asp:FormView ID="FormView1" runat="server"
DataKeyNames="case_id"
DataSourceID="SqlDataSource_OC"
DefaultMode="Insert"
OnItemInserted="formview1_Item_Inserted"
onpageindexchanging="FormView1_PageIndexChanging">
<InsertItemTemplate>
<table>
<tr>
<td>criticality_id:</td>
<td>
<asp:DropDownList ID="criticality_idTextBox"
runat="server"
Text='<%# Bind("txt_criticality_id","{0:D}") %>'
DataSourceID="SqlDataSource_Criticality"
DataTextField="ut_value"
DataValueField="criticality_id"
AppendDataBoundItems="true">
<asp:ListItem Value="0"
Text="--Select Level--"
Selected="True" />
</asp:DropDownList>
<br />
</td>
</tr>
<tr>
<td>case_num:</td>
<td>
<asp:TextBox Name="txt_case_num"
ID="case_numTextBox"
runat="server"
Text='<%# Bind("txt_case_num") %>' /> **<------ This is the textbox the value needs to go into. It will be hidden so the user wont see it**
<br />
</td>
</tr>
<tr>
<td>title:</td>
<td>
<asp:TextBox ID="titleTextBox"
runat="server"
Text='<%# Bind("txt_title") %>' />
<br />
</td>
</tr>
<tr>
<td>description:</td>
<td>
<asp:TextBox ID="descriptionTextBox"
runat="server"
Text='<%# Bind("txt_description") %>' TextMode="MultiLine" />
<br />
</td>
</tr>
<tr>
<td>external_email_address:</td>
<td>
<asp:TextBox ID="external_email_addressTextBox"
runat="server"
Text='<%# Bind("txt_external_email_address") %>' />
<br />
</td>
</tr>
</table>
<asp:LinkButton ID="InsertButton"
runat="server"
CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton"
runat="server"
CausesValidation="False"
CommandName="Cancel"
Text="Cancel" />
</InsertItemTemplate>
</asp:FormView>
<!--Datasource-->
<asp:SqlDataSource ID="SqlDataSource_OC"
runat="server"
ConnectionString="<%$ ConnectionStrings:OC_ConnectionString %>"
InsertCommand="INSERT INTO utcasesTest(created_by_user_id, status_id, criticality_id, project_id, case_num, is_active, description, title, created_by_timestamp, modified_by_timestamp, modified_by_user_id, is_external, external_email_address, object_id, object_type_id) VALUES (#txt_created_by_user_id, #txt_status_id, #txt_criticality_id, #txt_project_id, #txt_case_num, #txt_case_num **<-------This is where the value is passed to the DB**, #txt_description, #txt_title, getdate(), getdate(), #txt_modified_by_user_id, #txt_is_external, #txt_external_email_address, #txt_object_id, #txt_object_type_id)"
SelectCommand="SELECT utcasesTest.* FROM utcasesTest">
<InsertParameters>
<asp:Parameter Name="txt_created_by_user_id" DefaultValue="1" />
<asp:Parameter Name="txt_status_id" DefaultValue="1" />
<asp:Parameter Name="txt_criticality_id" />
<asp:Parameter Name="txt_project_id" DefaultValue="1" />
<asp:Parameter Name="txt_case_num" /> **<----------Paramater Definition**
<asp:Parameter Name="txt_is_active" DefaultValue="Y" />
<asp:Parameter Name="txt_description" />
<asp:Parameter Name="txt_title" />
<asp:Parameter Name="txt_created_by_timestamp" />
<asp:Parameter Name="txt_modified_by_timestamp" />
<asp:Parameter Name="txt_modified_by_user_id" DefaultValue="1" />
<asp:Parameter Name="txt_is_external" DefaultValue="Y" />
<asp:Parameter Name="txt_external_email_address" />
<asp:Parameter Name="txt_object_id" DefaultValue="-1" />
<asp:Parameter Name="txt_object_type_id" DefaultValue="-1" />
</InsertParameters>
</asp:SqlDataSource>
<!--Data source for criticallity dropdown-->
<!--Change Project ID to select criticality from right Binder: id 3 = GNRM-->
<asp:SqlDataSource ID="SqlDataSource_Criticality"
runat="server"
ConnectionString="<%$ ConnectionStrings:OCConnectionString_utcriticality %>"
SelectCommand="SELECT project_id, ut_value, criticality_id FROM utcriticality WHERE (project_id = 3)"
onselecting="SqlDataSource1_Selecting">
</asp:SqlDataSource>
<!--End data source for criticallity dropdown-->
</div>
</form>
</body>
</html>
Related
I'm a bit stumped here trying to change the alias of the column names for C# asp.net page in Visual Studio 2012. This page let's users search/filter filter data by columns, TankNum, CL and date range. I want the gridview column name of TankNum to be Tank.
The full code is below:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView" DataSourceID="SqlDataSource1" CellPadding="5" AllowPaging="True" PageSize="5" runat="server" AutoGenerateColumns="true">
<HeaderStyle BackColor="#989898" ForeColor="white" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=Computer\sqlexpress;Initial Catalog=DB;Integrated Security=True"
SelectCommand="SELECT TankNum, GD, CL FROM tblHistory2"
FilterExpression="GD >= '#{0}#' AND GD <= '#{1}#' AND TankNum LIKE '{2}%' AND CL LIKE '{3}%'">
<FilterParameters>
<asp:ControlParameter Name="Date" ControlID="tbDateFrom" Type="DateTime" PropertyName="Text" />
<asp:ControlParameter Name=" Date" ControlID="tbDateTo" Type="DateTime" PropertyName="Text" />
<asp:ControlParameter ControlID="txtTankNum" Name="TankNum" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false" />
<asp:ControlParameter ControlID="txtCL" Name="CL" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false" />
</FilterParameters>
</asp:SqlDataSource>
<br />
<th>Tank</th>
<td><asp:TextBox ID="txtTankNum" runat="server" Width="96px"> </asp:TextBox>Clock </td>
<td ><asp:TextBox ID="txtCL" runat="server" Width="104px"></asp:TextBox></td>
<p></p>
Enter the Date Range:
<p>
</p>
<td><asp:TextBox ID="tbDateFrom" runat="server" ReadOnly = "false">01/01/2000</asp:TextBox></td>
<td > </td>
<td><asp:TextBox ID="tbDateTo" runat="server" ReadOnly = "false">12/31/2017</asp:TextBox></td>
<input type="submit" id="Submit1" runat="server" />
</div>
</form>
</body>
</html>
I tried to do:
SelectCommand="SELECT TankNum AS Tank, GD, CL FROM tblHistory2"
but I get this error: Cannot find column [TankNum].
Again, this works fine I just can't figure how to change the alias names of the columns. Any suggestions?
I am new here and a beginner with APS and VB, I do have SQL experience. the problem I am having is I am trying to select two values in a VB aspx page.
one is a text box which can be types into, the other is a value which is selected from a drop downlist that looks as a table in my SQL database.
I want both values once entered and selected to be entered as a new row into another table of the same database, but I am getting the following error. and its driving me round in circles.
A ControlID must be specified in ControlParameter 'Product_Name'.
my code is as below, I suspect it is something simple that I am missing but I cannot see it for looking, can anyone help please?
<table style="width:100%;">
<tr>
<td>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert">
<InsertItemTemplate>
Product_Name:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="Product_Name" DataValueField="Product_Name">
</asp:DropDownList>
<ItemTemplate>
Product_Description:
<asp:TextBox ID="Product_DescriptionTextBox" runat="server" Text='<%# Bind("Product_Description") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Incident_TrackerConnectionString %>" InsertCommand="INSERT INTO [Incidents] ( [I_Product_Name], [I_Product_Description]) VALUES ( #Product_Name, #Product_Description)">
<InsertParameters>
<asp:ControlParameter Name="Product_Name" Type="String" />
<asp:Parameter Name="Product_Description" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Incident_TrackerConnectionString %>" SelectCommand="select Product_Name from dbo.products"></asp:SqlDataSource>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td class="auto-style2"></td>
<td class="auto-style2"></td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style1"></td>
<td class="auto-style1"></td>
</tr>
</table>
<br />
<br />
<br />
Thanks Kevin
You nee to specify the ControlID & PropertyName like this:-
<InsertParameters>
<asp:ControlParameter Name="Product_Name" ControlID="DropDownList1"
PropertyName="SelectedValue" />
</InsertParameters>
Edit:-
Okay, since you are using FormView, you need to specify it like this:-
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource2" DataTextField="Product_Name"
DataValueField="Product_Name" SelectedValue=<%# Bind('Product_Name') %>>
</asp:DropDownList>
Then , bind the InsertParameters as:-
<InsertParameters>
<asp:Parameter Name="Product_Name" Type="String" />
<asp:Parameter Name="Product_Description" Type="String" />
</InsertParameters>
I've got a website where I want to be able to generate a list of videos available on my server. Once that user selects a video, it would take them to another page where it plays the video. So far, I've got no errors on either of the pages, but nothing is showing up either :(
Here's the code for my pages:
word.aspx
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/webvideos.mdb" SelectCommand="SELECT TOP 5 * FROM [Videos] WHERE ID=#ID AND Program LIKE 'Word'">
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" />
</SelectParameters>
</asp:AccessDataSource>
<asp:DataList ID="DataList1" runat="server" DataSourceID="AccessDataSource1" RepeatColumns="5">
<ItemTemplate>
<table>
<tr>
<td>
<asp:HyperLink ID="VidLink1" runat="server" Target="_blank" NavigateUrl='<%# "VideoPlayer.aspx?ID=" & Eval("ID") %>' >
<asp:Image ID="VidThumb" runat="server" ImageUrl='<%# "videos/TraningVideos/Thumbnails" & Eval("Thumbnail") %>' /></asp:HyperLink>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
And here's VideoPlayer.aspx:
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/webvideos.mdb"
SelectCommand="SELECT * FROM Video WHERE ID=#ID" >
<SelectParameters>
<asp:QueryStringParameter Name="ID" QueryStringField="ID" />
</SelectParameters>
</asp:AccessDataSource>
'
width="450" height="380">
' />
<param name="autostart" value="false" />
<param name="controller" value="true" />
</object>
<ASPNetFlashVideo:FlashVideo ID="FlashVideo1" runat="server" VideoURL="http://www.youtube.com/watch?v=okHuuMbIg1E">
</ASPNetFlashVideo:FlashVideo>
<ASPNetFlashVideo:FlashVideo ID="FlashVideo2" runat="server" VideoURL='<%# "~/videos/TrainingVideos/" & Eval("Filename") %>'>
</ASPNetFlashVideo:FlashVideo>
As you can see, I've even tried using a regular youtube link for the ASPNetFlashVideo control that I've been able to add, and it hasn't been working either. Any ideas?
My Table structure
Courses
Id
Description
Subjects
Id
Description
Courses (Relation to Courses table).
My code as follows
td>
<asp:DropDownList ID="ddlCourses" runat="server" DataSourceID="LinqCourses"
DataTextField="Description" DataValueField="Id"/>
<asp:LinqDataSource ID="LinqCourses" runat="server"
ContextTypeName= "DataAccess.SchoolStudyDataContext" Select="new (Description, Id)"
TableName="Courses" />
</td>
<td align="left" valign="top" class="style5" style="width: 124px">
<asp:DropDownList ID="ddlSubjects" runat="server" DataSourceID="LinqSubjects"
DataTextField="Description" DataValueField="Id"/>
<asp:LinqDataSource ID="LinqSubjects" runat="server"
ContextTypeName= "DataAccess.SchoolStudyDataContext" Select="new (Description,Courses,Id)"
TableName="Subjects" Where="Courses == #Id" />
<WhereParameters>
asp:ControlParameter ControlID="ddlCourses" Name="Id"
PropertyName="SelectedValue" Type="Int32" />
</WherePrameters>
<asp:DropDownList ID="ddlCourses" runat="server" DataSourceID="SqlDataSource1"
DataTextField="Description" DataValueField="Id"/>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>"
SelectCommand="SELECT [Description],[Courses],[Id] FROM [table_name] WHERE ([Courses ] = #Courses ) ">
<SelectParameters>
<asp:Parameter Name="Courses" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
This is not a exact answer but this might help i guess
Your Where Property is wrong. Change this (==):
Where="Courses == #Id" />
To this (=):
Where="Courses = #Id" />
Source: MSDN
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
I think the parameter has a property named defaultvalue, you can try set that to "" and change the query like (Gender = #gender OR #gender ="") and so on.