Rate not updating

2 posts, 0 answers
  1. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 20 Jul 2011 Link to this post

    I have a Rating control in a FormView which is populated using a SQLDataSource.

    <asp:FormView ID="FormView2" runat="server" DataKeyNames="IDProjectsMaster" 
        DataSourceID="sds_MasterProjects">
                                        <EditItemTemplate>
                                            <table cellpadding="3" cellspacing="0" style="width: 100%">
                                                <tr>
                                                    <td class="tbltd" style="width: 110px">
                                                        Project Subject:</td>
                                                    <td>
                                                        <asp:TextBox ID="SubjectTextBox" runat="server" 
                                                            Text='<%# Bind("Subject") %>' Width="400px" />
                                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                                            ControlToValidate="SubjectTextBox" ErrorMessage="*" Font-Bold="True" 
                                                            Font-Size="Medium" ForeColor="#FF3300"></asp:RequiredFieldValidator>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 110px">
                                                        Enter Date:</td>
                                                    <td>
                                                        <asp:Label ID="EnterDateLabel" runat="server" 
                                                            Text='<%# Bind("EnterDate","{0:d}") %>' />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 110px">
                                                        Completion Date:</td>
                                                    <td>
                                                        <telerik:RadDatePicker ID="RadDatePicker2" Runat="server" 
                                                            Culture="English (United States)" DbSelectedDate='<%# Bind("ResolutionDate") %>'>
                                                            <Calendar ID="Calendar2" Runat="server" UseColumnHeadersAsSelectors="False" 
                                                                UseRowHeadersAsSelectors="False" ViewSelectorText="x">
                                                            </Calendar>
                                                            <DatePopupButton HoverImageUrl="" ImageUrl="" />
                                                            <DateInput ID="DateInput2" Runat="server" DateFormat="M/d/yyyy" DisplayDateFormat="M/d/yyyy">
                                                            </DateInput>
                                                        </telerik:RadDatePicker>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 110px">
                                                        Technician: </td>
                                                    <td>
                                                        <asp:DropDownList ID="ddl_IDAssignedTech" runat="server" 
                                                            AppendDataBoundItems="True" DataSourceID="sds_Technician" 
                                                            DataTextField="FullName" DataValueField="ActiveDirID" 
                                                            Text='<%# Bind("IDAssignedTech") %>'>
                                                            <asp:ListItem Text="Select" Value="0" />
                                                            <asp:ListItem Text="Team" Value="1" />
                                                        </asp:DropDownList>
                                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                                            ControlToValidate="ddl_IDAssignedTech" ErrorMessage="*" Font-Bold="True" 
                                                            Font-Size="Medium" ForeColor="#FF3300"></asp:RequiredFieldValidator>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 110px">
                                                        Priority:</td>
                                                    <td>
                                                        <telerik:RadRating ID="RadRating1" Runat="server" ReadOnly="True" 
                                                            Skin="WebBlue" Value='<%# Eval("Priority") %>'>
                                                        </telerik:RadRating>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 110px">
                                                        Project Deadline:</td>
                                                    <td>
                                                        <telerik:RadDatePicker ID="RadDatePicker3" Runat="server" 
                                                            Culture="English (United States)" 
                                                            DbSelectedDate='<%# Bind("ResolutionDeadline") %>'>
                                                            <Calendar ID="Calendar3" Runat="server" UseColumnHeadersAsSelectors="False" 
                                                                UseRowHeadersAsSelectors="False" ViewSelectorText="x">
                                                            </Calendar>
                                                            <DatePopupButton HoverImageUrl="" ImageUrl="" />
                                                            <DateInput ID="DateInput3" Runat="server" DateFormat="M/d/yyyy" 
                                                                DisplayDateFormat="M/d/yyyy">
                                                            </DateInput>
                                                        </telerik:RadDatePicker>
                                                    </td>
                                                </tr>
                                            </table>
                                            <h2>
                                                Project Details:</h2>
                                            <table cellpadding="0" cellspacing="0" style="width: 100%">
                                                <tr>
                                                    <td style="width: 101px">
                                                         </td>
                                                    <td>
                                                        <asp:TextBox ID="tbx_Projects" runat="server" Text='<%# Bind("MasterProject") %>' 
                                                            Height="100px" TextMode="MultiLine" Width="625px" />
                                                    </td>
                                                </tr>
                                            </table>
                                            <h2>
                                                Comments:</h2>
                                            <table cellpadding="0" cellspacing="0" style="width: 100%">
                                                <tr>
                                                    <td style="width: 101px">
                                                         </td>
                                                    <td>
                                                        <asp:TextBox ID="tbx_Comment" runat="server" Text='<%# Bind("Comment") %>' 
                                                            Height="100px" TextMode="MultiLine" Width="625px" />
                                                    </td>
                                                </tr>
                                            </table>
                                            <h2>
                                                Notes:</h2>
                                            <table cellpadding="0" cellspacing="0" style="width: 100%">
                                                <tr>
                                                    <td style="width: 101px">
                                                         </td>
                                                    <td>
                                                        <asp:TextBox ID="tbx_Notes" runat="server" Text='<%# Bind("Notes") %>' 
                                                            Height="100px" TextMode="MultiLine" Width="625px" />
                                                    </td>
                                                </tr>
                                            </table>
                                            <br />
                                            <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" 
                                                CommandName="Update" Text="Update" />
                                             <asp:Button ID="UpdateCancelButton" runat="server" 
                                                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                                        </EditItemTemplate>
        <ItemTemplate>
                                            <table cellpadding="0" cellspacing="0" style="width: 100%">
                                                <tr>
                                                    <td>
                                                         </td>
                                                </tr>
                                            </table>
                                            <table cellpadding="3" cellspacing="0" style="width: 100%">
                                                <tr>
                                                    <td class="tbltd" style="width: 112px">
                                                        Project Subject:</td>
                                                    <td>
                                                      
                                                        <asp:Label ID="SubjectLabel" runat="server" style="font-weight: 700" 
                                                            Text='<%# Bind("Subject") %>' />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 112px">
                                                        Enter Date:</td>
                                                    <td>
                                                        <asp:Label ID="EnterDateLabel" runat="server" 
                                                            Text='<%# Bind("EnterDate","{0:d}") %>' />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 112px">
                                                        Deadline Date:</td>
                                                    <td>
                                                        <asp:Label ID="lbl_DealineDate" runat="server" 
                                                            Text='<%# Bind("ResolutionDeadline","{0:d}") %>' />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 112px">
                                                        Completion Date:</td>
                                                    <td>
                                                        <asp:Label ID="ResolutionDateLabel" runat="server" 
                                                            Text='<%# Bind("ResolutionDate","{0:d}")  %>' />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 112px">
                                                        Technician: </td>
                                                    <td>
                                                        <asp:Label ID="FullNameLabel" runat="server" 
                                                            Text='<%# Bind("FullName") %>' />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 112px">
                                                        Priority:</td>
                                                    <td>
                                                        <telerik:RadRating ID="RadRating1" Runat="server" ReadOnly="True" 
                                                            Skin="WebBlue" Value='<%# Eval("Priority") %>'>
                                                        </telerik:RadRating>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="tbltd" style="width: 112px">
                                                        Project Deadline:</td>
                                                    <td>
                                                        <asp:Label ID="ResolutionDeadlineLabel" runat="server" 
                                                            Text='<%# Bind("ResolutionDeadline","{0:d}")  %>' />
                                                    </td>
                                                </tr>
                                            </table>
                                            <h2>
                                                Project Details:</h2>
                                            <table cellpadding="0" cellspacing="0" style="width: 800px">
                                                <tr>
                                                    <td style="width: 101px">
                                                         </td>
                                                    <td>
                                                        <asp:Label ID="ProjectLabel" runat="server" Text='<%# Eval("MasterProject").ToString().Replace(Environment.NewLine,"<br />") %>' />
                                                    </td>
                                                </tr>
                                            </table>
                                            <h2>
                                                Comments:</h2>
                                            <table cellpadding="0" cellspacing="0" style="width: 800px">
                                                <tr>
                                                    <td style="width: 101px">
                                                         </td>
                                                    <td>
                                                        <asp:Label ID="CommentLabel" runat="server" Text='<%# Eval("Comment").ToString().Replace(Environment.NewLine,"<br />") %>' />
                                                    </td>
                                                </tr>
                                            </table>
                                            <h2>
                                                Notes:</h2>
                                            <table cellpadding="0" cellspacing="0" style="width: 800px">
                                                <tr>
                                                    <td style="width: 101px">
                                                         </td>
                                                    <td>
                                                        <asp:Label ID="NotesLabel" runat="server" Text='<%# Eval("Notes").ToString().Replace(Environment.NewLine,"<br />") %>' />
                                                    </td>
                                                </tr>
                                            </table>
                                            <br />
            <asp:Button ID="EditButton" runat="server" CausesValidation="False" 
                CommandName="Edit" Text="Edit" />
             <asp:Button ID="Button2" runat="server" Text="Delete" onclick="Button2_Click" />
        </ItemTemplate>
    </asp:FormView>


    <asp:SqlDataSource ID="sds_MasterProjects" runat="server" 
        ConnectionString="<%$ ConnectionStrings:IT_CentralConnectionString %>" 
        DeleteCommand="DELETE FROM [ITC_ProjectsMaster]" 
        InsertCommand="" 
        SelectCommand="SELECT [IDProjectsMaster], [EnterDate], [ResolutionDeadline], [ResolutionDate], [FullName], [Subject], [MasterProject], [Priority], [Comment], [Notes], [IDAssignedTech] FROM [vw_ITC_Projects_Masters] WHERE [IDProjectsMaster] = @IDProjectsMaster" 
        UpdateCommand="UPDATE [ITC_Projects_Masters] SET [EnterDate] = @EnterDate, [ModifiedDate] = @ModifiedDate, [IDModifiedUser] = @IDModifiedUser, [ResolutionDeadline] = @ResolutionDeadline, [ResolutionDate] = @ResolutionDate, [IDAssignedTech] = @IDAssignedTech, [Subject] = @Subject, [MasterProject] = @MasterProject, [Priority] = @Priority, [Comment] = @Comment, [Notes] = @Notes WHERE [IDProjectsMaster] = @IDProjectsMaster">
        <InsertParameters>
            <asp:Parameter Name="EnterDate" Type="DateTime" />
        </InsertParameters>
        <SelectParameters>
            <asp:QueryStringParameter Name="IDProjectsMaster" QueryStringField="IDProjectsMaster" 
                Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="EnterDate" Type="DateTime" />
            <asp:Parameter Name="ModifiedDate" Type="DateTime" />
            <asp:Parameter Name="IDModifiedUser" Type="Int32" />
            <asp:Parameter Name="ResolutionDeadline" Type="DateTime" />
            <asp:Parameter Name="ResolutionDate" Type="DateTime" />
            <asp:Parameter Name="IDAssignedTech" Type="String" />
            <asp:Parameter Name="Subject" Type="String" />
            <asp:Parameter Name="MasterProject" Type="String" />
            <asp:Parameter Name="Priority" Type="Decimal" />
            <asp:Parameter Name="Comment" Type="String" />
            <asp:Parameter Name="Notes" Type="String" />
            <asp:Parameter Name="IDProjectsMaster" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>

    My issue is that when I attempt to update the data, the rating is not updated and the field value is ste to null.

    How can I use the Rating control in the update portion of the formview?

    Thanks in advance.













  2. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 25 Jul 2011 Link to this post

    Hello Allan,

    I created a sample project, based on the code snippet that you sent and I was able to reproduce similar issue - after every update the value of the RadRating is lost. In order to solve the problem I made sure that the value of the rating is preserved by adding it to the update parameters in the Updating server-side event of SqlDataSource. The example below demonstrates this:
    protected void Sqldatasource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
    {
        e.Command.Parameters["@UnitsInStock"].Value = ((RadRating)Formview1.FindControl("UnitsInStock")).Value;
    }
    UnitsInStock is the ID of the RadSlider used in this example.

    As the RadRating control usually accepts Value of type Decimal, please cast the specified value to that type:
    <telerik:RadRating ID="UnitsInStock" runat="server" Skin="WebBlue" ReadOnly="true" Value='<%# Convert.ToDecimal(Eval("UnitsInStock")) %>'>

    I have attached my test page so that you can use it as a basis for your further development.

    If the information listed above does not help you resolve your difficulties please provide more detailed description of your scenario, as well as steps to reproduce the encountered problem.

    Regards,
    Slav
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top