网格视图搜索多个下拉列表和文本框 [英] Grid view search through multiple drop down lists and text boxes

查看:64
本文介绍了网格视图搜索多个下拉列表和文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我使用Visual Studio的经验是拖放控件并使用UI来操作数据。我正在尝试构建一个具有标准姓氏(文本框),专业(下拉列表)和位置(下拉列表)的搜索页面的应用程序。所有数据都在一个SQL表中。如果用户将所有字段留空并单击搜索按钮,则他/她应获取数据库表中可用的所有记录。如果用户填写一个字段,则仅搜索该字段,其余字段应返回所有记录。结果应该放在第二页的列表中。

在所有记录列表中,我希望用户能够点击所需记录并在第三页中获取该特定记录的详细信息。我试图在Google上搜索此方案,但找不到任何内容。有人可以帮我构建这个应用程序或者给我一篇文章吗?

先谢谢你们。

Hello, My experience with Visual Studio is drag and drop controls and use UI to manipulate data. I am trying to build an application that would have a search page with criteria Last Name (text box), Specialty (Drop Down List), and Location (Drop Down List). All the data is in one SQL table. If user leave all the fields blank and click the search button, he/she should gets all the records available in the database table. If user fill one field, only that field is searched and rest of the fields should return all the records. The result should come in a list in second page.
In the list of all records, I want user to have ability to click on a required record and get the detail of that particular record in third page. I tried to search this scenario on Google and couldn't find anything. Can some one help me to build this application or point me to an article?
Thanks in advance guys.

推荐答案





我已经制作了一个示例代码,很容易理解如何开始你的任务..

i已经完成了编码数据..而不是硬编码使用来自db的数据..

chk评论......



---------- -------------------------------------------------- -------------------------------------------------- --------------------

Page 1:aspx



Hi,

I have made a sample code , it wil be easy to get an idea how to start ur task..
i have done harcoded data.. instead of hardcoding use the data from db..
chk the comments ...

----------------------------------------------------------------------------------------------------------------------------------
Page 1 : aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery.js.js"></script>
    <script type="text/javascript">

    </script>


</head>
<body>
    <form id="form1" runat="server">

        <table>
            <tr>
                <td>Last Name</td>
                <td>
                    <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td>Speciality</td>
                <td>
                    <asp:DropDownList ID="ddlSpeciality" runat="server">
                        <asp:ListItem Text="" />
                        <asp:ListItem Text="aaa" />
                        <asp:ListItem Text="bbb" />
                        <asp:ListItem Text="ccc" />
                    </asp:DropDownList></td>
            </tr>
            <tr>
                <td>Location</td>
                <td>
                    <asp:DropDownList ID="ddlLocation" runat="server">
                        <asp:ListItem Text="" />
                        <asp:ListItem Text="bangalore" />
                        <asp:ListItem Text="chennai" />
                        <asp:ListItem Text="hyderabad" />
                    </asp:DropDownList></td>
            </tr>
            <tr>

                <td colspan="2" align="center">
                    <asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" /></td>
            </tr>
        </table>


    </form>
</body>
</html>









page1 cs file







page1 cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string lastName = txtLastName.Text.Trim();
            string speciality = ddlSpeciality.Text;
            string location = ddlLocation.Text;
            Response.Redirect(string.Format("page2.aspx?lastname={0}&speciality={1}&location={2}",lastName ,speciality , location));


        }
    }


}











__________________________________________________________________________________________________________________________



第2页aspx








__________________________________________________________________________________________________________________________

page 2 aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="page2.aspx.cs" Inherits="WebApplication1.test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <asp:GridView ID="gvdata" runat="server">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:LinkButton ID="lnkID"  OnClick="LinkButton1_Click" Text="Details" runat="server"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>




        </div>
    </form>
</body>
</html>













第2页cs文件









page 2 cs file

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) { }
            else
            {
                string lastname = Request.QueryString["lastname"];
                string speciality = Request.QueryString["speciality"];
                string location = Request.QueryString["location"];

                string query = lastname.Length == 0 ? "" : "lastname ='" + lastname + "' and";
                query += speciality.Length == 0 ? "" : "speciality ='" + speciality + "' and";
                query += location.Length == 0 ? "" : "location ='" + location + "' ";

                query = query.Trim().TrimStart(new char[] { 'a', 'n', 'd' }).TrimEnd(new char[] { 'a', 'n', 'd' });

                query = "select * from tablename where " +( query.Length == 0 ? "1=1" : query);
                // use this query to get data from sql database
                // use shld get the data from db
                // for example, i  have hardcoded the datatable with some  values

                DataTable dt = new DataTable();
                dt.Columns.Add("ID", typeof(int));
                dt.Columns.Add("lastname", typeof(string));
                dt.Columns.Add("speciality", typeof(string));
                dt.Columns.Add("location", typeof(string));
                dt.Rows.Add(1, "karthik", "aaa", "bangalore");
                dt.Rows.Add(2, "parthip", "aaa", "chennai");
                dt.Rows.Add(3, "krishna", "aaa", "hyderabad");


                gvdata.DataSource = dt;
                gvdata.DataBind();



            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            string id  = ((sender as LinkButton).Parent.Parent as GridViewRow).Cells[1].Text;
            Response.Redirect("page3.aspx?id=" + id);
        }
    }
}









______________________________________________________________________________________________________________________________



page3 aspx file







______________________________________________________________________________________________________________________________

page3 aspx file

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="page3.aspx.cs" Inherits="WebApplication1.page3" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div runat="server" id="divcontent">
        </div>
    </form>
</body>
</html>











page3 cs file






page3 cs file

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class page3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) { }
            else
            {
                 string id = Request.QueryString["id"];
                // use this id to fetch the data from db to get the details.

                 // get the data from db..
                // i have hardcoded
                 DataTable dt = new DataTable();
                 dt.Columns.Add("ID", typeof(int));
                 dt.Columns.Add("lastname", typeof(string));
                 dt.Columns.Add("speciality", typeof(string));
                 dt.Columns.Add("location", typeof(string));
                 dt.Rows.Add(1, "karthik", "aaa", "bangalore");
                 Table tbl = new Table() { CellPadding=1 , CellSpacing=2 , BorderColor = System.Drawing.Color.Red, BorderWidth=1 };
                 
                 foreach (DataColumn col in dt.Columns)
                 {
                     TableRow tr = new TableRow() { BorderWidth=1 , BorderColor = System.Drawing.Color.Red };
                     tr.Cells.Add( new TableCell () { BorderWidth=1 , BorderColor = System.Drawing.Color.Red ,Text = col.ColumnName});
                     tr.Cells.Add( new TableCell () { BorderWidth=1 , BorderColor = System.Drawing.Color.Red ,Text = dt.Rows[0][col].ToString()});
                     tbl.Rows.Add(tr);

                    }

                 divcontent.Controls.Add(tbl);
                 }


            
        }
    }
}


You need to improve your Google search skills, check this article & customize it.

GridView-Search Control[^]
You need to improve your Google search skills, check this article & customize it.
GridView-Search Control[^]


for this you can use like function in sql to retrieve the required data.
for this you can use like function in sql to retrieve the required data.


这篇关于网格视图搜索多个下拉列表和文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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