I have a drop down list that comes from a sqldatasource that is presented in alphabetical order. Because of this, the lists index numbers do not line up at all with the primary keys within the SQL table. I need to be able to set the drop down list's selection on page load based on primary key information I have.
<asp:DropDownList ID="catagoryDropDown" runat="server" DataSourceID="SqlDataSource3"
DataTextField="Catagory" DataValueField="PK_SupportCatagory" CssClass="dropDownList">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$
ConnectionStrings:ApplicationServices %>"
SelectCommand="SELECT [PK_SupportCatagory], [Catagory] FROM [SupportCatagory] ORDER BY CASE
WHEN [PK_SupportCatagory] = 1 THEN 1 ELSE 2 END, [Catagory]">
</asp:SqlDataSource>
My thought is to get the string by querying the database using that to set the drop down list appropriately.
catagoryDropDown.SelectedValue = "Sick Leave";
The above does not work. How would I accomplish this? Is there a better way to do this?