如何使用文本框搜索记录 [英] how to search the records using textbox

查看:81
本文介绍了如何使用文本框搜索记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

在我的Web窗体上,我有一个文本框,一个按钮和一个gridview来搜索数据.
在gridview中,我有9列和40,000条记录.(在Gridview中使用分页)


请问您可以建议我如何搜索所有9列.

谢谢,

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,

推荐答案


检查此示例将指导您.
Hi,
check this Example will Guide you.
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();
    }





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



最好的问候
M.Mitwalli



Best Regards
M.Mitwalli


我认为这些代码项目文章可能对您有所帮助
具有分页和过滤功能的自定义GridView [
I think these Code Project articles may be helpful to you
Custom GridView with Paging and Filtering[^]


你好,请检查
希望对您有帮助
http://datatables.net/examples/basic_init/alt_pagination.html [如何对所有列进行排序& GridView的分页 [
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


这篇关于如何使用文本框搜索记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆