Problem with non data bound value in ASP.NET DropDownList.

Posted by ProfK on Stack Overflow See other posts from Stack Overflow or by ProfK
Published on 2010-05-09T07:54:45Z Indexed on 2010/05/09 7:58 UTC
Read the original article Hit count: 181

Filed under:

I'm trying to 'inject' an [All Regions] item into my regions dropdown, as follows:

    <asp:DropDownList ID="regionList" runat="server" AutoPostBack="true" AppendDataBoundItems="true" Width="200px" DataSourceID="regionDataSource" DataTextField="Desc"
        DataValueField="RegionId">
        <asp:ListItem Selected="True" Value="">[All Regions]</asp:ListItem>
    </asp:DropDownList>

I also have a rank dropdown, for taxi ranks in a region, with the following select parameter:

<asp:ControlParameter ControlID="regionList" Name="RegionId" PropertyName="SelectedValue" Type="Int32" DefaultValue="" ConvertEmptyStringToNull="true" />

So the expected behaviour is that when [All Regions] is selected, the ranks dropdown should get a null parameter, and mt SQL selects all ranks, for all regions. I know my SQL works with a null parameter, but the ranks dropdown is not data binding when I select [All Regions] on the region list. It binds when I select a region from the DB, but keeps that binding when I select [All Regions] again. What am I doing wrong?

© Stack Overflow or respective owner

Related posts about ASP.NET