Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Dear Friends,

on my webform, i have a textbox and a button and gridview to search the data.
IN gridview i have 9 columns and 40,000 records in it.(Used Paging in Gridview)


Please can u suggest me how to search all the 9 columns.

Thanks,
Posted
Updated 15-Apr-12 22:08pm
v2

Hi,
check this Example will Guide you.
C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bind();
        }
    }
    DataTable dt = new DataTable();
    void bind()
    {
        using (
              SqlConnection con =
                  new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString))
        {

            SqlCommand cmd = new SqlCommand("select  *  from dbo.Orders ", con);
            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(dt);
            GridView1.DataSource = null;
            GridView1.DataSource = dt;
            GridView1.DataBind();
            ViewState.Add("dt", dt);
            cmd.Dispose();

        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        dt = (DataTable)ViewState["dt"];
        if (ViewState["flag"] != null)
        {
            if ((bool)ViewState["flag"] == true)
            {
                GridView1.DataSource = null;
                dt = (DataTable)ViewState["dt"];
                DataView dvwData = new DataView(dt);
                dvwData.RowFilter = "orderID =" + Convert.ToInt32(TextBox1.Text) + "";
                GridView1.DataSource = dvwData;
                GridView1.DataBind();
            }
        }
        else
        {
            bind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ViewState.Add("flag", true);
        dt = (DataTable)ViewState["dt"];
        DataView dvwData = new DataView(dt);
        dvwData.RowFilter = "orderID ="+Convert.ToInt32(TextBox1.Text)+"";
        GridView1.DataSource = dvwData;
        GridView1.DataBind();
    }


ASP.NET
<div>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
            onpageindexchanging="GridView1_PageIndexChanging" PageSize="5">
        </asp:GridView>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>


Best Regards
M.Mitwalli
 
Share this answer
 
v6
Comments
Syed SufiyanUddin 16-Apr-12 4:45am    
please can u send me complete code
Mohamed Mitwalli 16-Apr-12 14:43pm    
check the solution i hope it help you
Best regards
M.Mitwalli
Nelek 16-Apr-12 16:36pm    
People here will help you with problems, but I don't think you'll get a full solution. That is your work.
Mohamed Mitwalli 16-Apr-12 14:44pm    
This Filter instead of going to Data base and bring the whole Data .
I think these Code Project articles may be helpful to you
Custom GridView with Paging and Filtering[^]
 
Share this answer
 
Comments
Syed SufiyanUddin 16-Apr-12 4:11am    
Boss, I need to search using Textbox not dropdown. PLEASE SUGGEST ME
hello Check with this
I hope this will help you
http://datatables.net/examples/basic_init/alt_pagination.html[^]

how to perform sorting for all columns & paging for GridView[^]
There is an excellent jquery plugin which does paging,searching & sorting
EnJoy Coding
 
Share this answer
 
u can search with query sql it is simply u

select *
from tabel
where textbox = 'columns1' OR textbox = 'columns2' OR ... textbox = 'columns9'

u must rank the columns how is more important for you
 
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