So I have two dropdownlists, the first containing items from a datasource with values of a GUID and a static item.
<asp:DropDownList runat="server" ID="CategoryDDL" DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="categoryID" AutoPostBack="True" AppendDataBoundItems="True" >
<asp:ListItem Value="(Select Category)">(New Category)</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionString%>" SelectCommand="SELECT categoryID, Name FROM category"></asp:SqlDataSource>
The other dropdownlist is very similiar, but as a control parameter set to read the value of the first, and again contains a static item.
<asp:DropDownList runat="server" ID="itemDDL" DataSourceID="SqlDataSource2" DataTextField="item" DataValueField="itemID">
<asp:ListItem Value="(Select Item)">(New Question)</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionString%>" SelectCommand="SELECT itemID, categoryID, item FROM Items WHERE (categoryID = @categoryID)">
<SelectParameters>
<asp:ControlParameter ControlID="CategoryDDL" Name="categoryID" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
How can I get the dropdownlist to ignore the value of my first value if it doesn’t exist in the second. Or better yet, is there a way I can call the SQL datasource from code and populate the dropdownlist?
Added
OnSelecting="SqlDataSource2_Selecting"to the second Dropdownlist so that it will cancel the selecting command if it can’t get a valid GUID.