Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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...
ASP.NET
<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
SQL
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
Updated 29-Sep-12 21:39pm
v3
Comments
Sandeep Mewara 30-Sep-12 3:44am    
And the issue is?
Raj.Rautela 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

Hi.

i think you should first bind to database and then select it :

try this code in your pageload:

C#
 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 { }
            }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900