i want to make a seacrh page using c# in asp.net..
at the first page, i want to display all the record in a gridview..then,after user click a search button, the result will appear in another gridview..
what should i put to visible the previous gridview and display only the result..
here are my code:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="search.aspx.cs" Inherits="search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<asp:TextBox ID="catID" runat="server" MaxLength="1"></asp:TextBox><asp:Button ID="button2" runat="server" Text="Search" onclick="button2_Click" /><br />
<asp:CompareValidator ID="CompareValidator1" runat="server" Text="Please Enter the Category ID" ControlToValidate="catID" Type="Integer" Operator="DataTypeCheck"></asp:CompareValidator>
<asp:GridView ID="GridView1" runat="server" DataKeyNames="categoryID" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="categoryID" HeaderText="Category ID" ReadOnly="true" SortExpression="categoryID" />
<asp:BoundField DataField="CategoryName" HeaderText="Category Name" SortExpression="CategoryName" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
</Columns>
</asp:GridView>
<asp:GridView ID="GridView2" runat="server" DataKeyNames="categoryID" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="categoryID" HeaderText="Category ID" ReadOnly="true" SortExpression="categoryID" />
<asp:BoundField DataField="CategoryName" HeaderText="Category Name" SortExpression="CategoryName" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
</Columns>
</asp:GridView>
</asp:Content>
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
public partial class search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
catID.Focus();
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds = new DataSet();
string cmdString = "SELECT * FROM Categories";
con = new SqlConnection("Server=(local); Database=test; user id=sa; password=itdept");
cmd = new SqlCommand(cmdString, con);
con.Open();
da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
con.Close();
}
protected void button2_Click(object sender, EventArgs e)
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds = new DataSet();
var cateID = catID.Text;
string cmdString = "SELECT * FROM Categories WHERE categoryID = ' " + cateID + " ' ";
con = new SqlConnection("Server=(local); Database=test; user id=sa; password=itdept");
cmd = new SqlCommand(cmdString, con);
con.Open();
da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
}