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

problem with AddHandler

2 Answers 157 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nikita Yaroshevsky
Top achievements
Rank 1
Nikita Yaroshevsky asked on 30 Jan 2011, 01:51 AM
Hi I have a Telerik RadGrid and I'm trying to hook up my own event to RadRating control placed inside the ItemTemplate of the grid.
The added handler does not fire..

<telerik:RadGrid ID="RadGrid1" EnableViewState="False" OnPageIndexChanged="RadGrid1_PageIndexChanged"
                runat="server" DataSourceID="SqlDataSource1" GridLines="None" Width="850px" Height="100%"
                Skin="Telerik" PageSize="20" AllowPaging="True">
                <PagerStyle Mode="NumericPages" PageButtonCount="1" Position="TopAndBottom" />
                <MasterTableView BorderStyle="None" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
                    PageSize="20">
                    <NoRecordsTemplate>
                        <div>
                            Nothing was found, start your search again. To Refresh, click <a href="inventory.aspx?reset=no&make=clear&model=clear&yearFromGrid=clear">
                                here</a></div>
                    </NoRecordsTemplate>
                    <Columns>
                        <telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID" UniqueName="ID"
                            DataType="System.Int32" ReadOnly="True" Visible="False" AutoPostBackOnFilter="True">
                        </telerik:GridBoundColumn>
                    </Columns>
                 <itemTemplate>
                  <asp:UpdatePanel runat="server" ID="panel1">
                                                                                <ContentTemplate>
                                                                                <telerik:RadRating ID="RadRating1" Value="3.5" runat="server" AutoPostBack="false"  Precision="Exact" />
                                                                                </ContentTemplate>
                                                                                </asp:UpdatePanel>
 
</ItemTemplate>
                    <EditFormSettings>
                        <FormTemplate>
                        </FormTemplate>
                    </EditFormSettings>
                    <PagerStyle Mode="NumericPages" Position="TopAndBottom" />
                </MasterTableView>
                <ActiveItemStyle BorderStyle="None" />
            </telerik:RadGrid>


Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
    If Not IsPostBack Then
 
 
        For Each gridDataItem As GridDataItem In RadGrid1.Items
            Dim radRate As RadRating = DirectCast(gridDataItem.FindControl("RadRating1"), RadRating)
            AddHandler radRate.Rate, AddressOf CControls_UnitGrid.Rate
 
            radRate.Value = 1
            radRate.AutoPostBack = True
            Dim panel1 As UpdatePanel = DirectCast(gridDataItem.FindControl("panel1"), UpdatePanel)
            AddHandler panel1.Load, AddressOf CControls_UnitGrid.Rate
        Next
    End If
End Sub

Shared Sub Rate(ByVal sender As Object, ByVal e As EventArgs)
        Dim radRate As RadRating = DirectCast(sender, RadRating)
 
        radRate.Value = 2
    End Sub

Here is my codeBehind, what am I doing wrong?

2 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 02 Feb 2011, 03:22 PM
Hi Nikita,

I checked your code, and I would first suggest that you remove the ASP:UpdatePanel from the grid. You can replace it with RadAjaxPanel. Then try modifying the ItemCreated event handler as below:


Private Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
            Dim gridDataItem as GridDataItem = CType(e.Item, GridDataItem)
            Dim radRate As RadRating = DirectCast(gridDataItem.FindControl("RadRating1"), RadRating)
            AddHandler radRate.Rate, AddressOf CControls_UnitGrid.Rate
   
            radRate.Value = 1
            radRate.AutoPostBack = True
End Sub

Let me know if it works thus.

Greetings,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Nikita Yaroshevsky
Top achievements
Rank 1
answered on 03 Feb 2011, 10:38 PM
Yes it worked, I have taken it out of itemtemplate AND turned on the viewstate on the grid. Thanks for help!
Tags
General Discussions
Asked by
Nikita Yaroshevsky
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Nikita Yaroshevsky
Top achievements
Rank 1
Share this question
or