Populate gridview based on databound dropdown list selectedvalue change

2k views Asked by At

I have an asp.net application for membership management. One page needs to have a gridview which is populated based on a dropdown list of statuses. I initially thought about hard-coding with a Select Case, but then remembered that the dropdown list is databound and needs to be dynamic (because the admin-level users have another page to change the statuses). I'm still new at this, and my searches are not turning up anything. Any links or examples would be helpful. Thanks.

1

There are 1 answers

1
Pawan Nogariya On BEST ANSWER

I would suggest to use OnSelectedIndexChanged event of dropdownlist for your purpose with AutoPostBack property set to true, something like this

<asp:DropDownList runat="server" ID="ddlStatus" OnSelectedIndexChanged="ddlStatus_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>

And on your code behind page you can bind your grid differently for different selected values in your event handler, something like this

protected  void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
{
    if (ddlStatus.SelectedItem.Value == "RequiredValue")
    {
        // bind grid in some way
    }
    else
    {
        // bind grid in some other way
    }
}

This will work irrespective of your binding the dropdownlist options dynamically or having them hard coded.