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

Rebinding Grid From Within User Control Form

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 03 Jun 2009, 02:12 PM
I have an application that uses a formview within the Grid's NestedViewTemplate to display additional record data:
<telerik:RadGrid ID="grid_applications" runat="server"  
.... 
<NestedViewTemplate> 
    <asp:Label ID="GridRec" runat="server" Visible="false" Text='<%# Eval("record") %>' /> 
       <uc1:AppViewer ID="AppViewer1" runat="server" /> 
    </NestedViewTemplate> 

Inside the UserControl I have a FormView to display all the additional data.  All of this works fine.

However, I have a RadComboBox that I use to perform an update of status when the user selects something.  This column is found on the main grid so when they make a change I want the main grid to display the new value immediately, I cant get it to work.  I thought I could just rebind the main grid like so:
Protected Sub list_appState_SelectedIndexChanged(ByVal o As ObjectByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) 
 
        Dim record As Integer = (TryCast(Parent.FindControl("GridRec"), Label)).Text 
        Dim AppState As String = (TryCast(formview_AppInfo.FindControl("list_appState"), RadComboBox)).SelectedValue 
 
        Dim UpdateSuccess As Integer = Apps.UpdateAppState(record, AppState) 
 
        If UpdateSuccess > 0 Then 
            lbl_status.Text = String.Format("<br />The Application Status has been updated to '{0}' for record: {1}.<br /><br />", AppState, record) 
            Dim grid As RadGrid = (TryCast(Parent.FindControl("grid_applications"), RadGrid)) 
            grid.Rebind() 
        Else 
 
        End If 
 
    End Sub 

However on that rebind I get the error:

Object reference not set to an instance of an object.


Should I not be able to reference the grid just as I do other controls on the parent and then rebind it?


1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 05 Jun 2009, 01:36 PM
Hi Shawn,

You can use the NamingContainer object of the combo box to get a reference to the RadGrid control. For example, if the combo box is within an edit form of the grid, the code for accessing the latter becomes as follows:

Dim grid As RadGrid = TryCast(DirectCast(DirectCast(sender, RadComboBox).NamingContainer, GridEditFormItem).OwnerTableView.OwnerGrid, RadGrid) 

I hope this helps.

All the best,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Shawn
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or