Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Search records using textbox and button controls present in first web page and display it’s corresponding records in datalist in second web page

 by Satyapriya Nayak on Jan 17, 2012

In this blog we will know how to search records using textbox and button controls present in first web page and display it’s corresponding records in datalist in second web page.
Download Files: Datalist textbox search.rar
Comments: 0 Views: 464 Printable Version 

In this blog we will know how to search records using textbox and button controls present in first web page and display it's corresponding records in datalist in second web page.

 

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="First.aspx.cs" Inherits="First" %>

 

<!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>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <asp:Label ID="Label1" runat="server" Text="Search" Font-Bold="True"></asp:Label>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

   

    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

    </div>

    </form>

</body>

</html>

 

 

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

 

public partial class First : System.Web.UI.Page

{

   

    protected void Button1_Click(object sender, EventArgs e)

    {

        Response.Redirect("Second.aspx?id=" + TextBox1.Text);

 

    }

}

 

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Second.aspx.cs" Inherits="Second" %>

 

<!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>

</head>

<body>

    <form id="form1" runat="server">

    <div>

     <asp:DataList ID="DataList1" runat="server">

    <FooterStyle BackColor="#FFCC00" ForeColor="#FF3300" />

        <EditItemStyle BackColor="#FF8080" />

        <AlternatingItemStyle BackColor="#FFFF99" />

<HeaderTemplate>

 

</HeaderTemplate>

    <ItemTemplate>

                        <table border="1">

                        <tr>

                        <th>Id</th>

                        <th>Name</th>

                        <th>Price</th>

                        </tr>

                        <tr>

                        <td><%#Eval("mid")%></td>

                        <td><%#Eval("mname")%></td>

                        <td><%#Eval("mprice")%></td>

                        </tr>

                        </table>

                        </ItemTemplate>

    </asp:DataList>

    </div>

    </form>

</body>

</html>

 

 

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

public partial class Second : System.Web.UI.Page

{

    string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

    SqlCommand com;

    string s1;

    string str;

    protected void Page_Load(object sender, EventArgs e)

    {

        s1 = Request.QueryString["id"];

        SqlConnection con = new SqlConnection(connStr);

        con.Open();

        str = "select count(*)from Mobile where mname='" + s1 + "'";

        com = new SqlCommand(str, con);

        int count = Convert.ToInt32(com.ExecuteScalar());

        if (count > 0)

        {

            bindlist();

        }

        else

        {

            Response.Write("Sorry No records found");

        }

      

    }

    void bindlist()

    {

        SqlConnection con = new SqlConnection(connStr);

        con.Open();

        str = "select * from Mobile where mname='" + s1 + "'";

        com = new SqlCommand(str, con);

        SqlDataReader reader;

        reader = com.ExecuteReader();

        DataList1.DataSource = reader;

        DataList1.DataBind();

        reader.Close();

        con.Close();

    }

}

 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
Nevron Gauge for SharePoint
Become a Sponsor

 Blogger's Profile
Age: Not Available
Location:
Title: Student
Joined: Aug 02, 2010
Education: Bachelors Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.