2
我正在使用下面的代碼來綁定我的datagridview
和select
語句以獲取我需要的記錄。通過在文本框中鍵入來篩選
一切工作正常在這些代碼行,但我想自動過濾記錄時,用戶鍵入的東西到textbox
和何時刪除數據,記錄返回到初始狀態,當窗體加載。任何人都可以給我一些提示嗎?
這裏是我的代碼:
public nir()
{
InitializeComponent();
nir_load();
}
void nir_load()
{
string cs = "Data Source=IS020114\\CODRINMA;Initial Catalog=gcOnesti;Integrated Security=True";
string select = "select p.cod as Numar, p.data as Data, p.doc_cod as NrDocFurnizor, g.nume as Gestiune, c.nume as Furnizor, p.validat as Validat, p.facturat as Contat from primar p inner join gestiuni g on p.part2=g.gest_id inner join cf c on p.part1=c.cf_id where p.tip=2";
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand(select, con);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dataGridView1.DataSource = bs;
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
string cs = "Data Source=IS020114\\CODRINMA;Initial Catalog=gcOnesti;Integrated Security=True";
string select = "select p.cod as Numar, p.data as Data, p.doc_cod as NrDocFurnizor, g.nume as Gestiune, c.nume as Furnizor, p.validat as Validat, p.facturat as Contat from primar p inner join gestiuni g on p.part2=g.gest_id inner join cf c on p.part1=c.cf_id where cod='" +txtnr.Text+"' and data='" + dtpData.Value.ToString("yyyy-MM-dd") +"' and p.tip=2";
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand(select, con);
con.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dataGridView1.DataSource = bs;
}
}
在同樣的情況下我使用jQuery。在我的頁面上有一個輸入字段,在它下面有一個從SQL Server加載數據的div表。當用戶在輸入字段中鍵入內容時,將根據用戶輸入過濾下表。 – gofr1
請澄清:你想搜索,因爲標題暗示或過濾,因爲你的descrition沒有。這兩個人在這裏經常回答.. – TaW
@TaW - 要過濾,我解釋自己錯了。但是我可以使用'KeyUp'事件來做到這一點。 – cdrrrrrr