Hi,

I am using SqlDataSource in order to bind data to dropdownlist and looking for
a simple way to change text color based on specific value from database.

Any idea if I can manipulate the SqlDataSource to do that?
Is this something that I have to call from code-behind?

This is my controls:

<asp:DropDownList 
        ID="pageSelector" 
        runat="server" 
        AutoPostBack="True"
        DataTextField="p_name"
        DataValueField="pid"
        DataSourceID="SqlDataSource2">
        </asp:DropDownList>

        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:_ConStr1 %>" 
        ProviderName="<%$ ConnectionStrings:_ConStr1.ProviderName %>" 
        SelectCommand="SELECT [pid], [p_name], [p_active] FROM [pages] ORDER BY [pid]">
        </asp:SqlDataSource>

And I need something like that:

If DataReader("p_active") = "Yes" Then
   pageSelector.Items(DataReader("pid")).Attributes.Add("style", "color:Green")
Else
   pageSelector.Items(DataReader("pid")).Attributes.Add("style", "color:Red")
End If

Appriciate your help..

Thanks,
YP

Recommended Answers

All 2 Replies

I saw that article but it does not reflect my environment..

Any other ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.