Tuesday, June 10, 2014

Asp.Net - Drop down list filtration on gridview

Example :

Assume that you have two dropdownlist inside gridview , One is Department another one is Employee based on Department selection which you want to load Employees.

Sample :

protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            DropDownList ddlDepartment = (DropDownList)sender;

            GridViewRow gvr = (GridViewRow)ddl.NamingContainer;
            DropDownList ddlEmployee = gvr.FindControl("ddlEmployee ") as DropDownList;


            if (ddlDepartment.SelectedIndex > 0)
            {
                // Load employee details based on department.
            }

        }
        catch (Exception ex)
        {

        }

    }

1 comment: