Search and show GridView data in popup Window

This is a simple task for searching grid view and views the details of in grid view data in popup window (new browser).

Search.aspx (.aspx)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="Search" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .form
        {
            background-color: skyblue;
        }
        .div
        {
            right: 302px;
            left: 300px;
            height: 112px;
        }
        .div1
        {
            right: 302px;
            left: 10px;
            height: 112px;
        }
    </style>
</head>
<
body class="form">
    <form id="form1" runat="server">
    <div class="div" style="position: absolute; top: 42px;">
        <table>
            <tr>
                <td align="center">
                    <b>Know Your Application Status </b>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Panel ID="Panel1" runat="server">
       <asp:RadioButtonList ID="RadioButtonList1" runat="server"
                            RepeatDirection="Horizontal" Width="372px">
        <asp:ListItem Value="Id" Selected="True">Application ID</asp:ListItem>
         <asp:ListItem Value="Name">Applicant Name</asp:ListItem>
           <asp:ListItem Value="No">House Number</asp:ListItem>
                        </asp:RadioButtonList>                    
                    </asp:Panel>
                </td>
            </tr>
            <tr>
                <td align="center">
                    <asp:TextBox ID="txtSearchContect" runat="server" Width="197px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="center">
                    <asp:Button ID="btnsearch" runat="server" Text="Search" OnClick="btnsearch_Click" />
                </td>
            </tr>
        </table>
    </div>
    <div class="div1" style="position: absolute; top: 200px;">
        <table>
            <tr>
                <td align="left">
                    <asp:GridView ID="gvappdetails" AutoGenerateColumns="False" runat="server" Style="margin-left: 0px"
                        Width="916px" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px"
                        CellPadding="4" GridLines="Horizontal">
                        <RowStyle BackColor="White" ForeColor="#333333" />
                        <Columns>
                         <asp:BoundField HeaderText="APP ID" DataField="APPID" />
                            <asp:BoundField HeaderText="NAME" DataField="NAME" />
           <asp:BoundField HeaderText="RELATION NAME" DataField="RELATIONNAME" />

                    <asp:BoundField HeaderText="AGE" DataField="AGE" />
                <asp:BoundField HeaderText="HOUSE NO" DataField="HOUSENO" />
                            <%--<asp:BoundField HeaderText="AC NUMBER" DataField="[ACNUMBER&NAME]" />--%>
                            <asp:BoundField HeaderText="PART NO" DataField="PARTNO" />

                           <asp:TemplateField HeaderText="View Status?">
                                <ItemTemplate>
                                    <a href="javascript:window.open('Searchdetails.aspx?AppId=<%# Eval("APPID") %>','NewPage','width=400,height=500');">
                                        View Status</a>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <FooterStyle BackColor="White" ForeColor="#333333" />
                        <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />

                        <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</
html>

gridview.gif

Code Behind File (.aspx.cs)

using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Data.SqlClient;
 
public partial class Search : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\Administrator\\My
Documents\\Visual Studio 2008\\WebSites\\WebSite2\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True"
);
    public void fillgrid()
    {
        SqlCommand cmd = new SqlCommand("select APPID,NAME,RELATIONNAME,AGE,HOUSENO,PARTNO from APPLICANTDETAILS", con);
        DataSet ds = new DataSet();
        con.Open();
        SqlDataAdapter dap = new SqlDataAdapter(cmd);
        dap.Fill(ds, "APPLICANTDETAILS");
        gvappdetails.DataSource = ds.Tables[0].DefaultView;
        gvappdetails.DataBind();
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        //fillgrid();
    }   
    protected void btnsearch_Click(object sender, EventArgs e)
    {
     switch (RadioButtonList1.SelectedItem.Value)
        {
            case "Name":
                SqlCommand cmd = new SqlCommand("select APPID,NAME,RELATIONNAME,AGE,HOUSENO,PARTNO from APPLICANTDETAILS where Name='"
+ txtSearchContect.Text + "'", con);
                DataSet ds = new DataSet();
                con.Open();
                SqlDataAdapter dap = new SqlDataAdapter(cmd);
                dap.Fill(ds, "APPLICANTDETAILS");
                gvappdetails.DataSource = ds.Tables[0].DefaultView;
                gvappdetails.DataBind();
                break;
            case "No":
                SqlCommand cmd1 = new SqlCommand("select APPID,NAME,RELATIONNAME,AGE,HOUSENO,PARTNO from APPLICANTDETAILS where
HOUSENO='"
+ txtSearchContect.Text + "'", con);
                DataSet ds1 = new DataSet();
                con.Open();
                SqlDataAdapter dap1 = new SqlDataAdapter(cmd1);
                dap1.Fill(ds1, "APPLICANTDETAILS");
                gvappdetails.DataSource = ds1.Tables[0].DefaultView;
                gvappdetails.DataBind();
                break;
            default:
                SqlCommand cmd2 = new SqlCommand("select APPID,NAME,RELATIONNAME,AGE,HOUSENO,PARTNO from APPLICANTDETAILS where
APPID='"
+ txtSearchContect.Text + "'", con);
                DataSet ds2 = new DataSet();

                con.Open();
                SqlDataAdapter dap2 = new SqlDataAdapter(cmd2);
                dap2.Fill(ds2, "APPLICANTDETAILS");
                gvappdetails.DataSource = ds2.Tables[0].DefaultView;
                gvappdetails.DataBind();
                break;
 
        }
    }
 
}

SearchDetails.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Searchdetails.aspx.cs" Inherits="Searchdetails" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .span
        {
            right: 302px;
            left: 300px;
            height: 112px;
        }
        .body
        {
            background-color: skyblue;
        }
        .td{}
    </style>
</head>
<
body class="body">
    <form id="form1" runat="server">
    <div>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <asp:Label ID="Label1" runat="server" ForeColor="Red" Text="E - REGISTRATION USER STATUS"></asp:Label>
        <br />
        <table>
            <tr>
                <td>
                    APPLICATION ID
                </td>
                <td>
                    <asp:Label ID="lblappid" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    NAME
                </td> 
                <td>
                    <asp:Label ID="lblname" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    RELATION NAME
                </td>
                <td>
                    <asp:Label ID="lblrelationname" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    AGE
                </td>
                <td>
                    <asp:Label ID="lblage" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    HOUSE NO
                </td>
                <td>
                    <asp:Label ID="lblhno" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    PART NUMBER
                </td>
                <td>
                    <asp:Label ID="lblpartno" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    Application Date
                </td>
                <td>
                    <asp:Label ID="lblapplicationdate" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    STATUS
                </td>

                <td>
                    <asp:Label ID="lblstatus" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    REMARKS
                </td>
                <td>
                    <asp:Label ID="lblremarks" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td align="right"> 
                  <asp:Button ID="btnprint" runat="server" Text="Print" />
                 </td>
                <td>
                    <asp:Button ID="btnexit" runat="server" Text="Exit" />
                </td>
            </tr>
         </table>
    </div>
    </form>
</body>
</
html>

gridview1.gif

Code Behind file (SearchDetails.aspx.cs)

public partial class Searchdetails : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\Administrator\\My
Documents\\Visual Studio 2008\\WebSites\\WebSite2\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True"
);
    protected void Page_Load(object sender, EventArgs e)
    {
        string sql = "select * from APPLICANTDETAILS where APPID='" + Request.QueryString["AppId"] + "'";
        SqlCommand cmd = new SqlCommand(sql, con);
        con.Open();
        SqlDataReader Dr = cmd.ExecuteReader();
        if (Dr.Read() == true)
        {
            lblappid.Text = Dr[0].ToString();
            lblname.Text = Dr[1].ToString();
            lblrelationname.Text = Dr[2].ToString();
            lblage.Text = Dr[3].ToString();
            lblhno.Text = Dr[4].ToString();
            lblpartno.Text = Dr[6].ToString();
            lblapplicationdate.Text = Dr[7].ToString();
            lblstatus.Text = Dr[8].ToString();
            lblremarks.Text = Dr[9].ToString();
        }      
    }
}

Ebook Download
View all
Learn
View all