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

Rating and Database Update

6 Answers 73 Views
Rating
This is a migrated thread and some comments may be shown as answers.
Mike_T
Top achievements
Rank 1
Mike_T asked on 27 Feb 2011, 06:57 PM
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 .'.

6 Answers, 1 is accepted

Sort by
0
Niko
Telerik team
answered on 28 Feb 2011, 05:41 PM
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!
0
Mike_T
Top achievements
Rank 1
answered on 28 Feb 2011, 11:14 PM
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 .'.
0
Niko
Telerik team
answered on 01 Mar 2011, 09:59 AM
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!
0
Mike_T
Top achievements
Rank 1
answered on 01 Mar 2011, 10:57 AM
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 .'.
0
Accepted
Niko
Telerik team
answered on 01 Mar 2011, 11:51 AM
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!
0
Mike_T
Top achievements
Rank 1
answered on 01 Mar 2011, 01:15 PM
that worked perfect, thank you so much Nikodim for your help
Mike .'.
Tags
Rating
Asked by
Mike_T
Top achievements
Rank 1
Answers by
Niko
Telerik team
Mike_T
Top achievements
Rank 1
Share this question
or