Sending Initialization data to sub controls

1 posts, 0 answers
  1. Rich
    Rich avatar
    6 posts
    Member since:
    Apr 2007

    Posted 19 Mar 2015 Link to this post

    On several occasions I have had the need to send specific information to sub controls or Custom Edit forms when using Rad Grids.  I have seen in the forums that others have had this same issue.  However I have not seen any solutions to this issue. I have come up with two solutions that seem to work well.

    ------------------------------------------------------------------------
    The first solution is the use of Attributes:

    From the RsdGrid.ItemCommand handlerFor example I need to pass an ID to the edit form so that It knows what data to present. I also use multiple edit forms depending on the insert button selected. 

    Case Telerik.Web.UI.RadGrid.InitInsertCommandName

                   e.Canceled = True

                   RDG_List.EditIndexes.Clear()

                   Me.Attributes.Add("CompanyID", CompanyID.ToString)

                    e.Item.OwnerTableView.EditFormSettings.UserControlName = GT.Constant.Screen.GTCS0958_Security.ScreenCommonName

                   e.Item.OwnerTableView.InsertItem()

     

     

    In the Page load of the
    web user control for the edit form I do the following:

     

    If ChildControlsCreated = False Then

     If (TypeOf DataBinder.Eval(Parent.BindingContainer,"DataItem.RowID") Is System.DBNull) Then        
    ' in insert mode        
    CompanyID = CLng(CType(Parent.TemplateControl, System.Web.UI.UserControl).Attributes("CompanyID"))

     
    End if
    End if

     

    Note: You may have to
    play with the parent pointer till you find you original control because the
    parent is sometimes a grid table value not the original control.

     

     --------------------------------------------------------------------------------------------

    The Second solution is adding columns to the table:

    This method only works if you are editing a row that exists in the table. For an insert you do not pass any Parent.BindingContainer data so it will not work, hence the need for the first method. In my work I use data tables. In this case I want to pass a flag that tells the control to show different entry fields. When you press the edit row button on the grid it kicks off the needdatasource function prior to opening the custom edit form.

    In the
    RadGrid.NeedDataSource  handler

    Dim DataTable As System.Data.DataTable 
    -- call some function to get the data into the datatable

    DataTable.Columns.Add("ShowMemberRelationshipInfo", System.Type.GetType("System.Boolean")) 

    Dim v As Boolean = ShowMemberRelationshipInfo

    For Each r In DataTable.Rows   
    r("ShowMemberRelationshipInfo") = v

    Next 

    RadGrid.DataSource = DataTable   

    In the Custom Edit Form simply read the data as you do normally in the page load.  

    ShowMemberRelationshipInfo = CBool(DataBinder.Eval(Parent.BindingContainer, "DataItem.ShowMemberRelationshipInfo")) 

     
Back to Top