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

Event Bubbling from rad grid in user control

5 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 07 Jun 2010, 01:01 PM
Hi.  I am looking for code sample (VB.NET) to do something in the webpage when the user selects a row in the gridcontrol in a user control.  The user control code is listed below. 

<%

@ Control Language="VB" AutoEventWireup="false" CodeFile="YALReadOnlyGrid.ascx.vb" Inherits="UserControls_YALReadOnlyGrid" %>

 

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

 

 
<telerik:RadGrid ID="RadROGrid" runat="server"   
     AllowPaging="true" AllowSorting="True" GridLines="None" Skin="Sunset"   
    Width="275px">  
        <MasterTableView> 
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px" /> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px" /> 
            </ExpandCollapseColumn> 
        </MasterTableView> 
          
            
        <ClientSettings> 
            <Selecting AllowRowSelect="True" /> 
        </ClientSettings> 
</telerik:RadGrid> 


In the webpage, the user control is accessed as follows

<%@ Page Title="" Language="VB" MasterPageFile="~/Common/YALMasterPage.master" AutoEventWireup="false" CodeFile="YALDropDowns.aspx.vb" Inherits="Admin_YALDropDowns" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">  
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderHeader" Runat="Server">  
</asp:Content> 
<asp:Content ID="Content3" ContentPlaceHolderID="ConPHLeftTop" Runat="Server">  
    <YAL:YALROGenGrid runat="server" ID="YALDDVals" Source="DropDowns" setPageSize="50" /> 
</asp:Content> 
<asp:Content ID="Content4" ContentPlaceHolderID="ConPHLeftBottom" Runat="Server">  
</asp:Content> 
<asp:Content ID="Content5" ContentPlaceHolderID="ConPHRightTop" Runat="Server">  
</asp:Content> 


Thanks for any help and/or sample code that you can provide

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Jun 2010, 02:50 PM
Hello John,

The following code will help you to access the parent page and control placed in the parent page, when selecting the grid item.

CS:
 
    protected void RadGridinUC_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        RadGrid grid = (RadGrid)sender; 
        UserControl userControl = (UserControl)grid.NamingContainer; // User control where the grid is placed 
        Page pg = (Page)userControl.NamingContainer; // Parent page 
        TextBox txtBox = (TextBox)pg.FindControl("TextBox1"); // TextBox is placed in parent page 
        txtBox.Text = "hai"
    } 

[Also set the ClientSettings -> EnablePostBackOnRowClick propertry to True for grid]

-Shinu.
0
John
Top achievements
Rank 1
answered on 07 Jun 2010, 08:51 PM
Thanks Shinu!

What does the code on the web page need to be to get to the event.

- John
0
John
Top achievements
Rank 1
answered on 07 Jun 2010, 09:56 PM
Hi Shinu!

Do you also have the code sample for a VB.NET app? 

Thanks for your help.

- John
0
Shinu
Top achievements
Rank 2
answered on 09 Jun 2010, 06:15 AM
Hi John,

If you want to raise an event from user control to main page, then make use of event delegation technique. Here I found some useful links regarding 'implementing delegates'.
Raise event from user control to main page
Implementing Delegates

And you can easily convert C# code to its VB equivalent by using following code converter.
http://converter.telerik.com/

-Shinu.
0
John
Top achievements
Rank 1
answered on 15 Jun 2010, 07:03 PM
I will try that out and let you know how that works out.  Thanks for your help
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
John
Top achievements
Rank 1
Share this question
or