搜索数据库并将搜索结果显示在列表视图或数据列表的另一页中 [英] Search database and display search result in another page in list view or data list

查看:74
本文介绍了搜索数据库并将搜索结果显示在列表视图或数据列表的另一页中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的表单..我想搜索数据库并在列表视图或数据列表的另一页中显示搜索结果.不知道如何执行此操作...

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  
)

推荐答案

Hi.

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

try this code in your pageload:

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 { }
            }


这篇关于搜索数据库并将搜索结果显示在列表视图或数据列表的另一页中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆