使用文本框和按钮从GRIDVIEW搜索记录 [英] SEARCHING RECORD FROM GRIDVIEW Using Textbox and button

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

问题描述

亲爱的所有人,

在我的网络表单中,我有一个文本框,按钮和gridview.
我需要从gridview搜索记录.

在gridview中,我总共有8列,我需要搜索6列的记录.

请点击以下链接以供参考:与我所需要的相同.

Dear All,

In my webform i have a textbox, button and gridview.
I need to search the record from gridview.

In gridview i have total 8 columns, and i need to search records for 6 columns.

Chk this below link for Reference: same as it is I need.

http://www.yvr.ca/en/flight-information/arriving.aspx.

Please help me, and send me code in detail. am beginner to Asp.net.


Thanks.

推荐答案



我尝试了一些代码供您检查,请检查一次

Hi ,

I tried some code for your requirement check it once

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script language ="javascript" >
        function getresult() {


.get(' GetMyResults.aspx',{GetFindRes:
.get('GetMyResults.aspx', { GetFindRes:


(" #txtfindresult").val()},文档 .getElementById(" ) .innerHTML =数据; }); } < / 脚本 > < /head > < 正文 > < 表单 =" form1" runat >服务器" > < div > < 输入 =" 文本" id txtfindresult" onkeydown =" getresult()" > br / > < div =" resultsdiv" < /div > < /div > < /form > < /body > < /html >
("#txtfindresult").val() }, function (data) { document.getElementById("resultsdiv").innerHTML = data; }); } </script> </head> <body> <form id="form1" runat="server"> <div> <input type="text" id="txtfindresult" onkeydown="getresult()" /><br /> <div id="resultsdiv"> </div> </div> </form> </body> </html>



之后,我们需要编写一些代码以基于文本框中的键入文本来检索数据



After this we need to write some code to retrieve data based on typed text in textbox

//In page load of GetMyResults.aspx.cs
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["GetFindRes"] != null)
        {
            Response.Clear();
            string searchtext = Request.QueryString["GetFindRes"].ToString();
            string query = "select  * from FlightDetails where Schedtime='" + searchtext + "%' or airline='" + searchtext + "%' or flightname='" + searchtext + "%' or arfrom='" + searchtext + "%' or flightstatus='" + searchtext + "%' or Gate='" + searchtext + "%'";
            SqlConnection con = new SqlConnection("");
            SqlDataAdapter da = new SqlDataAdapter(query, con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            string outputresult = "<table style="width: 672px; visibility: visible;"><thead><table><tbody><tr><th class="schedTime sorting_asc" style="width: 151px;">Sched Time</th><th class="airline sorting" style="width: 90px;">Airline</th><th class="flightNumber sorting" style="width: 98px;">Flight #</th><th class="city sorting" style="width: 169px;">Arriving From</th><th class="remark sorting" style="width: 92px;">Status</th><th class="gate sorting" style="width: 71px;">Gate</th></tr></tbody></table></thead>";
            foreach (DataRow dr in dt.Rows)
            {
                outputresult = outputresult + "<tr class="odd"><td class="sorting_1">"+dr["Schedtime"].ToString()+"</td><td class=""><a title="Go to airline website" rel="external" href="http://www.westjet.com">WestJet</a></td><td class="">WS2057</td><td class="">Cancun (CUN)</td><td class="">Arrived at 03:29</td><td class="">D66</td></tr>";
            }
            outputresult = outputresult + "</table>";
            Response.Write(outputresult);
            Response.End();
        }
    }



在上面的代码中,我使用jquery以异步方式显示结果

我希望你知道jQuery

在这里,我仅供参考,您可以使用自己的数据库或进程

最好的



In the above code i used jquery to display results in asynchronous

I hope u know jquery

Here I just made it for reference only you can use ur own DB or process

All the Best


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

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