如何使用gridview进行搜索 [英] How to search using gridview
本文介绍了如何使用gridview进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我希望有效的分页,排序,
我想通过从下拉列表中获取值并在gridview中填充来进行搜索
请帮帮我
谢谢
Chandran
Hi
I want to have effective paging,sorting,
I want to do searching by getting values from dropdownlist and populate inside gridview
Please help me
Thanks
Chandran
推荐答案
[ ^ ]
http://www.aspsnippets.com/Articles/Search-GridView-records-data-on-TextBox-KeyPress-using-jQuery-in-ASPNet.aspx [ ^ ]
http://www.youtube.com/watch?v=QERuo8L6J4U [ ^ ]
-KR
[^]
http://www.aspsnippets.com/Articles/Search-GridView-records-data-on-TextBox-KeyPress-using-jQuery-in-ASPNet.aspx[^]
http://www.youtube.com/watch?v=QERuo8L6J4U[^]
-KR
请添加一个下拉列表在其属性中设置Autopostback = true。还要添加数据网格。
Please add one dropdownlist and set Autopostback = true in its properties. Also add a datagrid.
Public Partial Class WebForm3
Inherits System.Web.UI.Page
Public oCn As New System.Data.SqlClient.SqlConnection("Data Source=(local);Initial Catalog=MyDatabase;Uid=sa")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Me.IsPostBack = False Then
fill_ddl()
End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
fill_data()
End Sub
Sub fill_data()
If oCn.State = ConnectionState.Closed Then
oCn.Open()
End If
Dim cmd As New SqlClient.SqlCommand("select * from mst_employees where name='" & Me.DropDownList1.SelectedItem.Text & "'", oCn)
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim ds As New DataSet("bpl")
Dim i As Integer = 0
da.Fill(ds, "bpl")
Me.GridView1.DataSource = ds.Tables(0)
Me.GridView1.DataBind()
oCn.Close()
End Sub
Sub fill_ddl()
If oCn.State = ConnectionState.Closed Then
oCn.Open()
End If
Dim cmd As New SqlClient.SqlCommand("select name from mst_employees", oCn)
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim ds As New DataSet("bpl")
Dim i As Integer = 0
da.Fill(ds, "bpl")
If ds.Tables(0).Rows.Count > 0 Then
Me.DropDownList1.Items.Add("Select an Item")
While (i <> ds.Tables(0).Rows.Count)
Me.DropDownList1.Items.Add(ds.Tables(0).Rows(i).Item("Name").ToString)
i = i + 1
End While
End If
Me.DropDownList1.DataBind()
oCn.Close()
End Sub
End Class
尝试
带有过滤器的ASP.NET Gridview [ ^ ]
带有搜索选项的ASP.NET GridView(SearchableGridView) [ ^ ]
在GridView中搜索记录 [ ^ ]
Try
ASP.NET Gridview with Filter in Header[^]
ASP.NET GridView with search option (SearchableGridView)[^]
Search Records in GridView[^]
这篇关于如何使用gridview进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文