I’ve got a Databound DropDownList control that is filled with the following query:
<asp:DropDownList ID="ddlSelector" runat="server" DataSourceID="dataSelector"
DataTextField="Description" DataValueField="Description"
OnSelectedIndexChanged="TextBox_TextChanged"
AutoPostBack="True">
</asp:DropDownList>
<asp:SqlDataSource ID="dataSelector" runat="server"
ConnectionString="<%$ ConnectionStrings:PRODUCTION %>"
SelectCommand="SELECT [ID], [Description] FROM [Status]">
</asp:SqlDataSource>
I have a second Databound DropDownList control who’s values need to be selected from the next available Status.ID.
<asp:DropDownList ID="ddlChangeTo" runat="server" DataSourceID="dataChangeTo"
DataTextField="Description" DataValueField="Description">
</asp:DropDownList>
<asp:SqlDataSource ID="dataChangeTo" runat="server"
ConnectionString="<%$ ConnectionStrings:PRODUCTION %>"
SelectCommand="SELECT [ID], [Description] FROM [Status] WHERE ([Description] < @Description)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlSelector" Name="Description" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
The WHERE clause above does not fit the solution I am after. It is filtering alphabetically.
What I need is a way to get the [ID] value from ddlSelector and put all values greater than that ID into my ddlChangeTo control.
How do I get the [ID] value from the ddlSelector DropDownList control to use in the Databinding query for the ddlChangeTo DropDownList control?
OK, I found out how to do this, but I did not find the answer online anywhere.
After starring at the code for a bit and trying various ways, it appears that
DataTextFieldis what is displayed whileDataValueFieldis the value that is used for comparison.This may be obvious to those of you who have done this for a long time, but it was not for me.
To get my control to work, I made the following change to the
DataValueFieldof theddlSelectorDropDownList control:I had to make a similar change to the second Databound DropDownList control, the
SqlDataSource, and theControlParameterType:Such a cool feeling when you figure it out yourself.
I hope others get some use out of this.