ColorPicker in a DetailView

4 posts, 1 answers
  1. Michael Barbu
    Michael Barbu avatar
    12 posts
    Member since:
    Feb 2010

    Posted 20 Apr 2010 Link to this post

    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?
  2. Answer
    Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 21 Apr 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael Barbu
    Michael Barbu avatar
    12 posts
    Member since:
    Feb 2010

    Posted 21 Apr 2010 Link to this post

    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?
  5. Michael Barbu
    Michael Barbu avatar
    12 posts
    Member since:
    Feb 2010

    Posted 21 Apr 2010 Link to this post

    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
Back to Top