Click here to Skip to main content
15,916,188 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Richard C Bishop 22-Nov-13 16:46pm    
An article will more than likely not exist that has the exact criteria you are requesting. You best bet is to break it down into smaller pieces and tackle them one at a time.

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

XML
<%@ 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

C#
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));


        }
    }


}





__________________________________________________________________________________________________________________________

page 2 aspx

XML
<%@ 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>






page 2 cs file

C#
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

XML
<%@ 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
C#
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);
                 }


            
        }
    }
}
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 23-Nov-13 9:12am    
Is this fine??
Member 3844829 25-Nov-13 8:41am    
Thanks Karthik. I am working with it.
Karthik_Mahalingam 26-Nov-13 10:37am    
cool :)
You need to improve your Google search skills, check this article & customize it.
GridView-Search Control[^]
 
Share this answer
 
Comments
Member 3844829 25-Nov-13 8:29am    
Thanks buddy. I think Karthik got it and understood what I was asking. Thanks for your comment.
for this you can use like function in sql to retrieve the required data.
 
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