使用文本框和按钮从gridview搜索记录......... [英] Searching record from gridview using Textbox and button .........
本文介绍了使用文本框和按钮从gridview搜索记录.........的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友,
使用Texbox和来自gridview的按钮搜索数据.
===============================================
目前,我只从gridview搜索一个字段.
我需要从Gridview搜索Id,FirstName,LastName,UserName,Department.
这是我的代码.
Dear Frnds,
Search data using Texbox and button from gridview.
=================================================
Presently am searching only one field from gridview.
I need to search Id , FirstName, LastName,UserName, Department from Gridview.
This is my code.
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;
using System.Web.Configuration;
public partial class Admin_UsersLoginHistory : System.Web.UI.Page
{
string conString = ConfigurationManager.ConnectionStrings["KKIAConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
//if (Session["AdminName"] == "")
//{
// Response.Redirect("Default.aspx");
//}
if (!IsPostBack)
{
GridData();
}
}
protected void BtnSearch_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
// I need to search Id , FirstName, LastName,UserName, Department from Gridview.
SqlCommand cmd = new SqlCommand("Select * from UserLogs where UserName='" + TxtSearch.Text + "' ", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
private void GridData()
{
SqlConnection con = new SqlConnection(conString);
SqlCommand cmd = new SqlCommand("Select * from UserLogs", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
[edit]删除了SHOUTING,添加了代码块-OriginalGriff [/edit]
[edit]SHOUTING removed, Code block added - OriginalGriff[/edit]
推荐答案
从Codeproject中检查此链接
这是类似的问题
如何使用文本框搜索记录 [ ^ ]
享受编码
Check This Link From Codeproject
This Is similar quastion
how to search the records using textbox[^]
Enjoy Coding
在让我知道是否与您合作之前,请先检查一下已回答您的内容
此处 [
Hi,
Check this already answer you before let me know if did work with you
Here[^]
Best Regards
M.Mitwalli
因此,修改您的SELECT语句:
So modify your SELECT statement:
SELECT * FROM myTable WHERE FirstName='Joe' AND LastName='Smith' AND Department='Chemistry'
这篇关于使用文本框和按钮从gridview搜索记录.........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文