Vb.net – populating a gridview with a button’s click event

asp.netgridviewvb.net

I have a page that has two dropdownlists(one for the locations, and the other for departments), an employee search textbox and a button. On the other page, I have a gridview. Now, what I want to achieve is that when a user types an employee's name in the textbox control, selects a location from the location dropdownlist, and a department from the departments dropdownlist, and click the button(search), the gridview on the other page must show the required information of a SINGLE employee. Only one row must show.

I have created a database for the employees. I know how to do this with the autopostback but i have not tried it using a button's click. NB: the gridview should show only one row of a selected employee. I'm using ASP.NET VB

Your help will high appreciated.

Best Answer

Try this

<asp:Button ID="srchButton" Text="BindData" runat="server" OnClick="BindData" />

    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>

protected void BindData(object sender, EventArgs e)
{
    Gridview1.Datasource = YourDataSource;
    GridView1.DataBind()
}
Related Topic