Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 18-Mar-14 4:46am
v2
Comments
So, what is the issue?

Please add one dropdownlist and set Autopostback = true in its properties. Also add a datagrid.

VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900