This is a migrated thread and some comments may be shown as answers.

ColorPicker in a DetailView

3 Answers 93 Views
ColorPicker
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 20 Apr 2010, 05:51 PM
I'm trying to use a ColorPicker in a DetailView to allow a user to change the assigned color of a matching record. Below is my code:

<asp:TemplateField>   
<HeaderStyle/>   
<HeaderTemplate>AssignedColor:</HeaderTemplate>   
<EditItemTemplate><telerik:radcolorpicker ID="rcpAssignedColor" runat="server" preset="Standard" SelectedColor='<%#Bind("AssignedColor")%>'></telerik:radcolorpicker></EditItemTemplate>  
<ItemTemplate><%#Eval("AssignedColor")%></ItemTemplate>  
</asp:TemplateField>

But when I view the page with loaded data and switch to Edit mode I'm getting the following error on the EditItemTemplate line: System.InvalidCastException: Specified cast is not valid.

Is there another way to bind data to the ColorPicker control?

3 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetie
Telerik team
answered on 21 Apr 2010, 08:58 AM
Hello Michael Barbu,
For information how to bind the color picker control, please refer to our How to insert and update records in a RadGrid with columns that contain RadColorPicker knowledge base article. Even though the article is for a grid control, the approach for DetailsView is the same.

Greetings,
Tsvetie
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Michael
Top achievements
Rank 1
answered on 21 Apr 2010, 05:23 PM
Well, that got me 1 step closer. It is now displaying the HEX value from the database, but for some reason the value is not getting pulled by the DataSource. Is there something I'm missing?
0
Michael
Top achievements
Rank 1
answered on 21 Apr 2010, 06:11 PM
Thank you Tsvetie, you put me in the correct place. Here is what I have on the backend:
    Private ColorPicker As RadColorPicker  
 
    Protected Sub sdsTrack_Inserting(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles sdsTrack.Inserting, sdsTrack.Updating  
        Dim newAssignedColor As String 
        newAssignedColor = System.Drawing.ColorTranslator.ToHtml(ColorPicker.SelectedColor)  
        Dim sdsParam As New SqlParameter("@AssignedColor", newAssignedColor)  
        e.Command.Parameters.Add(sdsParam)  
 
        Me.gvwTrackList.DataBind()  
    End Sub 
 
    Protected Sub dvwTrack_ItemInserting(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvwTrack.ItemInserting  
        For Each row As DetailsViewRow In Me.dvwTrack.Rows  
            ColorPicker = CType(row.FindControl("rcpAssignedColor"), RadColorPicker)  
        Next 
    End Sub 
 
    Protected Sub dvwTrack_ItemUpdating(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles dvwTrack.ItemUpdating  
        For Each row As DetailsViewRow In Me.dvwTrack.Rows  
            ColorPicker = CType(row.FindControl("rcpAssignedColor"), RadColorPicker)  
        Next 
    End Sub 

Thanks again for your help
Tags
ColorPicker
Asked by
Michael
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Michael
Top achievements
Rank 1
Share this question
or