Ajax Rating Control - How do I call a server side function w/ multiple controls?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lamarant
    New Member
    • Nov 2007
    • 4

    Ajax Rating Control - How do I call a server side function w/ multiple controls?

    Hi...I'm trying to use the Rating Control in the Ajax Toolkit in a datalist. I have the control showing up in the list, with the logged in users current rating for each item in the list showing...

    Code:
    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatLayout="Flow">
         <ItemTemplate>            
                 <div class="Rating">
                     <ajaxToolkit:rating ID="SongRating" runat="server"
                         CurrentRating='<%# Eval("USERRATING") %>'
                         MaxRating="5"
                         StarCssClass="ratingStar"
                         WaitingStarCssClass="filledRatingStar"
                         FilledStarCssClass="filledRatingStar"
                         EmptyStarCssClass="emptyRatingStar"
                     />
                     <span class="SmallText">avg: <%# Eval("AVGRATING") %></span>
                  </div>
              
         </ItemTemplate>        
    </asp:DataList>

    When a user clicks on one of the rating controls, how would I go about calling a function (passing in the ID parameter from my datalist) that will execute the stored procedure I have to update the ratings table (I already have the stored proc...just need to know how to call a function with the rating control).

    I typically program in VB but I'll understand C# too.
  • lamarant
    New Member
    • Nov 2007
    • 4

    #2
    I figured this out. The trick is to use the "Tag" property offered in the rating control.

    Here's the sub routine:

    Code:
    Private Sub Rating_Changed(ByVal sender As Object, ByVal e As AjaxControlToolkit.RatingEventArgs)
            Dim SQL As String
            Dim ExecSP As New dbFun
            'run stored procedure
            SQL = "exec RateSong " & _
                    "@UserID=" & Request.Cookies("MLKLogin")("UserID") & ", " & _
                    "@AudioID=" & e.Tag.ToString & ", " & _
                    "@Rating=" & e.Value.ToString
            ExecSP.ExecuteSP(SQL)
    
    End Sub
    And here's the rating control:

    Code:
    <ajaxToolkit:rating ID="SongRating" runat="server"
                                CurrentRating='<%# Eval("USERRATING") %>'
                                MaxRating="5"
                                StarCssClass="ratingStar"
                                WaitingStarCssClass="filledRatingStar"
                                FilledStarCssClass="filledRatingStar"
                                EmptyStarCssClass="emptyRatingStar"
                                OnChanged="Rating_Changed"
                                Tag='<%# Eval("AUDIO_ID") %>'
                                AutoPostBack="false"
    />

    Comment

    Working...