Rating and Database Update

7 posts, 1 answers
  1. Mike_T
    Mike_T avatar
    36 posts
    Member since:
    Aug 2006

    Posted 27 Feb 2011 Link to this post

    Hello,

    I was lookig at this example http://demos.telerik.com/aspnet-ajax/rating/examples/gridrating/defaultcs.aspx 
    In order to update the database i inserted the ID column in the Grid, But i'm not sure what is the code that will allow me to retrieve the ID when i press to rate an item under this function Protected Sub RadRating1_Rate(sender As Object, e As EventArgs)


    Thanks much for your help
    mike .'.
  2. Niko
    Admin
    Niko avatar
    387 posts

    Posted 28 Feb 2011 Link to this post

    Hello Mike,

    First of all you should add a new column to the table. It can be a DataBound column with Display set to false:
    <telerik:GridBoundColumn UniqueName="DB_ID_Column" DataField="ID" Display="false" />
    In the rate event handler get the GridDataItem, as in the demo example, and use it as an indexed collection to get the text value of the column:
    Int32.Parse(gridDataItem("DB_ID_Column").Text)

    Hope this helps.

    Kind regards,
    Nikodim
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mike_T
    Mike_T avatar
    36 posts
    Member since:
    Aug 2006

    Posted 28 Feb 2011 Link to this post

    Hey Nikodim,

    I did exactly the same but i am getting an error in this: 'GridDataItem' is a type and cannot be used as an expression

     

    Protected Sub RadRating1_Rate(ByVal sender As Object, ByVal e As EventArgs)

     

     

     

    Dim oRating As RadRating = DirectCast(sender, RadRating)

     

     

     

    Dim dataItem As GridDataItem = DirectCast(oRating.Parent.Parent, GridDataItem)

     

     

     

    Dim x = Int32.Parse(GridDataItem("HymnID").Text)

     

    ........

     

    End Sub

     


    Thanks for your help
    mike .'.
  5. Niko
    Admin
    Niko avatar
    387 posts

    Posted 01 Mar 2011 Link to this post

    Hi Mike,

    You need to change the name of the variable to something other than GridDataItem. Otherwise the compiler cannot tell the variable from the type apart. You can, for example, change it to gridDataItem or currentDataItem.

    All the best,
    Nikodim
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  6. Mike_T
    Mike_T avatar
    36 posts
    Member since:
    Aug 2006

    Posted 01 Mar 2011 Link to this post

    Hey Nikodim,

    Thanks for your reply i'm still facing a problem in that declaration, can you please guide me more on how to do it?

    Dim currentDataItem As GridDataItem = DirectCast(sender, GridDataItem)
    Dim x = Int32.Parse(currentDataItem("HymnID").Text)

    i get the following error:
    Unable to cast object of type 'Telerik.Web.UI.RadRating' to type 'Telerik.Web.UI.GridDataItem'.

    Thanks,
    mike .'.
  7. Answer
    Niko
    Admin
    Niko avatar
    387 posts

    Posted 01 Mar 2011 Link to this post

    Hello Mike,

    The sender parameter is actually a RadRating(keep in mind that you have attached to a RadRating event). The GridDataItem is a parent control of the parent control of the RadRating. Therefore the code should be the following:
    Dim currentDataItem As GridDataItem = DirectCast(sender.Parent.Parent, GridDataItem)
    Dim x = Int32.Parse(currentDataItem("HymnID").Text)

    This change should do it.

    Best wishes,
    Nikodim
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  8. Mike_T
    Mike_T avatar
    36 posts
    Member since:
    Aug 2006

    Posted 01 Mar 2011 Link to this post

    that worked perfect, thank you so much Nikodim for your help
    Mike .'.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017