Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL Server
this my form..i want to search database and display search result in another page in list view or data list.having no idea how to do this...
            <table cellspacing="15" style="width:80%">
                <tr>
                    <td colspan="2" align="left">
                        <span style="font-size: small; font-family: Arial">Fields marked with 
                    </span> 
                    <span style="color: #FF3300; font-size: small; font-family: Arial;">*</span><span>
                            style="font-size: small; font-family: Arial"> are 
                    mandatory:
                                       
                    </span>
                                       
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="left">
                        <span style="text-decoration:none">
                        <span style="text-decoration: underline">Search Property For:</span></span><br /><br />
                        <asp:RadioButton ID="rbtnfs" selected="true" Text="For Sale" GroupName="radio" runat="server" >
                    
                    <asp:RadioButton ID="rbtnfr" Text="For Rent" GroupName="radio" runat="server" >  
                    <span style="font-size: x-small; font-family: Arial; ">       
                    <span style="text-decoration: underline">Select Atleast One Option</span></span><br />
                    <asp:Label ID="lblerror" ForeColor="Red" runat="server" Text="">
                       
                    </td>
                </tr>
                <tr>
                    <td style="width: 125px">
                        <span style="font-size: small; font-family: Arial">Keyword :</span> <span style="color: #FF0000">*</span>
                    </td>
                    <td style="width: 416px">
                        <asp:TextBox  ID="txtkeyword" runat="server" Width="167px" CssClass="validate[required,custom[onlyLetterSp]]">
                    </td>
                </tr>
                <tr>
                    <td style="width: 125px">
                        <span style="font-size: small; font-family: Arial">Property Type :
                    </span>
                    <span style="color: #FF0000">*</span></td>
                    <td style="width: 416px">
                        <asp:DropDownList ID="ddlpropertytype" runat="server" Width="169px" 
                            CssClass="validate[required] radio" 
                            >
                            <asp:ListItem Value="">--Select--
                            <asp:ListItem Value="cm">Commercial
                            <asp:ListItem Value="re">Residential
                        
                    </td>
                </tr>
                <tr>
                    <td style="width: 125px">
                        <span style="font-size: small; font-family: Arial">City :
                    </span>
                    <span style="color: #FF0000">*</span></td>
                    <td style="width: 416px">
                        <asp:DropDownList ID="ddlcity" runat="server" Width="169px" CssClass="validate[required] radio">
                            <asp:ListItem Value="">--Select--
                                    <asp:ListItem Value="mum">Mumbai
                                    <asp:ListItem Value="Dhl">Delhi
                        
                    </td>
                </tr>
                <tr>
                    <td style="width: 125px">
                        <span style="font-size: small; font-family: Arial">Locality :</span>
                    <span style="color: #FF0000">*</span></td>
                    <td style="width: 416px">
                        <asp:DropDownList ID="ddllocality" runat="server" Width="169px" CssClass="validate[required] radio">
                        <asp:ListItem Value="">--Select--
                                    <asp:ListItem Value="khg">Kharghar
                                    <asp:ListItem Value="Man">Mansarowar
                        
                    </td>
                </tr>
                <tr>
                    <td style="width: 125px">
                        <span style="font-size: small; font-family: Arial">Price :
                    </span>
                    <span style="color: #FF0000">*</span></td>
                    <td style="width: 416px">
                        <asp:DropDownList ID="ddlminprice" runat="server" Height="20px" CssClass="validate[required] radio">
                        <asp:ListItem Value="">--Select--
                        <asp:ListItem Value="cro">1 Crores
                        <asp:ListItem Value="lak">50Lakhs
                        
                        
                        <asp:DropDownList ID="ddlmaxprice" Width="85px" runat="server" Height="20px" CssClass="validate[required] radio">
                            <asp:ListItem Value="">--Select--
                        <asp:ListItem Value="cro">2 Crores
                        <asp:ListItem Value="lak">90 Lakhs
                        
                    </td>
                </tr>
                <tr>
                    <td style="width: 125px">
                        <span style="font-size: small; font-family: Arial">Bedroom :</span></td>
                    <td style="width: 416px">
                        <asp:DropDownList ID="ddlbedrooms" runat="server" Width="169px">
                            <asp:ListItem Value="">--Select--
                        <asp:ListItem Value="1">1
                        <asp:ListItem Value="2">2
                        <asp:ListItem Value="3">3
                        <asp:ListItem Value="4">4
                        <asp:ListItem Value="5">5
                        
                    </td>
                </tr>
                <tr>
                    <td style="width: 125px">
                        <span style="font-size: small; font-family: Arial">Built Up Area :</span>
                    <span style="color: #FF0000">*</span></td>
                    <td style="width: 416px" height="34px">
                        <asp:TextBox ID="txtminarea" runat="server" Height="18px" Width="53px" CssClass="validate[required,custom[number]]">
                         
                        <asp:TextBox ID="txtmaxarea" runat="server" Height="18px" Width="52px" CssClass="validate[required,custom[number]]">
                          
                        <asp:DropDownList ID="ddlarea" runat="server" CssClass="validate[required] radio">
                        <asp:ListItem Value="">--Select--
                        <asp:ListItem Value="fe">sqft
                        <asp:ListItem Value="me">sqm
                        <asp:ListItem Value="ya">sqyds
                        
                        
                    </td>
                </tr>
                <tr>
                    <td style="width: 125px">
                         
                    </td>
                    <td style="width: 416px">
                        <asp:Button class="btn" ID="btnSubmit" runat="server" Text="Search" Width="75px" 
                            onclick="btnSubmit_Click" />
                     <asp:Button class="btn" ID="btnreset" runat="server" Text="Reset" 
                            UseSubmitBehavior="false" Width="75px" onclick="btnreset_Click"/>
                    </td>
                </tr></table>
this is my database
create Table tbl_post_property_sale
(
	P_ID int identity(1,1)primary key,
	Property_Type varchar(50)not null,
	City_Id int references tbl_City(City_Id) not null,
	Locality_Id int references tbl_Locality(Locality_Id)not null,
	[Address] varchar(200)null,
	Pincode numeric null,
	Price varchar(20) not null,
	Bedrooms int null,
	Build_up_area varchar(20) not null,
	Key_Features varchar(200)null,
	Property_Image image not null,
	Name varchar(50)not null,
	Email varchar(50)not null,
	Mobile_No numeric not null  
)
Posted 29-Sep-12 21:35pm
Edited 29-Sep-12 21:39pm
v3
Comments
Sandeep Mewara at 30-Sep-12 3:44am
   
And the issue is?
raj rautela at 30-Sep-12 4:03am
   
issue is m not having any idea how to write code for my search from and display search result in datalist or listview..

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi.
 
i think you should first bind to database and then select it :
 
try this code in your pageload:
 
 SqlConnection conn = new SqlConnection();
            SqlTransaction trans = null;
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["Your ConnectionString name"].ConnectionString;
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            conn.Open();
            trans = cmd.Connection.BeginTransaction();
            try
            {
                cmd.CommandText = "selcet * from tbl_post_property_sale";
                cmd.Parameters.Add("@Property_Type  ", SqlDbType.VarChar).Value = textbox1.Text;
                cmd.Parameters.Add("@City_Id ", SqlDbType.NVarChar).Value = TextBox2.Text;
...
//try do the following for the rest of your Parameters in database
                trans.Commit();
                cmd.ExecuteScalar();
            }
            catch (SqlException se)
            {
                try
                {
                    trans.Rollback();
                }
                catch { Page.Title = "SqlException :" + se.Message; }
                try
                {
                    trans.Rollback();
                }
                catch (Exception ex)
                {
                    Page.Title = "Exception :" + ex.Message;
                }
            }
            finally
            {
                try
                {
                    conn.Close();
                }
                catch { }
            }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 599
1 OriginalGriff 419
2 CPallini 205
3 RyanDev 175
4 Sergey Alexandrovich Kryukov 170
0 OriginalGriff 5,649
1 Sergey Alexandrovich Kryukov 4,783
2 Peter Leow 2,954
3 Maciej Los 2,689
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web03 | 2.8.140718.1 | Last Updated 30 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid