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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top