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

Refresh RadGrid after delete item from another RadGrid

2 Answers 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michal
Top achievements
Rank 1
Michal asked on 05 Jun 2012, 11:46 AM
Hello,

My problem scenario:
I want to refresh second RadGrid after delete item from first RadGrid.
I tried use RadGridPrzedmiotyWydzialuBrakKatedry.Rebind()  
in code behind in method: --- protected void RadGridPrzedmiotyWydzialu_DeleteCommand --- 
but it doesn't work.

protected void RadGridPrzedmiotyWydzialu_DeleteCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.Item.Cells.Count > 0)
    {
        var db = DatabaseFactory.CreateDatabase();
        var cmd = db.GetStoredProcCommand("katw_Przedmioty_Katedr_upd");
 
        db.AddInParameter(cmd, "@idOsobaDziekan", DbType.Int32, MySession.IdOsoba);
        db.AddInParameter(cmd, "@idWydzial", DbType.Int32, MySession.IdWydzial);
        db.AddInParameter(cmd, "@idPrzedmiot", DbType.Int32, e.Item.Cells[2].Text);
        db.ExecuteNonQuery(cmd);
 
    }
//refresh my grid after delete item from first radgrid
    RadGridPrzedmiotyWydzialuBrakKatedry.Rebind();
    
}


I hope for you help.

First RadGrid  with SqlDataSource

<asp:SqlDataSource ID="SqlDataSourcePrzedmiotyWydzialu" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultDatabaseConnection %>"
    SelectCommand="katw_Przedmioty_Wydzialu_sel" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter ControlID="WydzialRadComboBox" Name="IdWydzial" PropertyName="SelectedValue"
            Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGridPrzedmiotyWydzialu">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGridPrzedmiotyWydzialu" LoadingPanelID="RadAjaxLoadingPanel" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGridPrzedmiotyWydzialuBrakKatedry">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGridPrzedmiotyWydzialuBrakKatedry" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadGrid ID="RadGridPrzedmiotyWydzialu" runat="server" AllowPaging="True"
    AutoGenerateColumns="False" CellSpacing="0" Culture="pl-PL" GridLines="None"
    HorizontalAlign="Justify" Skin="Simple" OnDeleteCommand="RadGridPrzedmiotyWydzialu_DeleteCommand"
    DataSourceID="SqlDataSourcePrzedmiotyWydzialu">
    <ClientSettings>
        <Selecting CellSelectionMode="None" AllowRowSelect="true" />
    </ClientSettings>
    <MasterTableView NoMasterRecordsText="Brak rekordów do wyÅ›wietlenia." DataKeyNames="IdPrzedmiot"
        CommandItemDisplay="Top" DataSourceID="SqlDataSourcePrzedmiotyWydzialu">
        <CommandItemSettings ExportToPdfText="Export to PDF" RefreshText="OdÅ›wież" ShowAddNewRecordButton="False" />
        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
            <HeaderStyle Width="20px" />
        </RowIndicatorColumn>
        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
            <HeaderStyle Width="20px" />
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridBoundColumn DataField="IdPrzedmiot" HeaderText="IdPrzedmiot" UniqueName="IdPrzedmiot"
                FilterControlAltText="Filter IdPrzedmiot column" DataType="System.Int32" SortExpression="IdPrzedmiot"
                ReadOnly="true" Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridButtonColumn CommandName="Edit" UniqueName="EditColumn" ButtonType="ImageButton"
                Text="Edytuj">
                <HeaderStyle Width="3%" />
            </telerik:GridButtonColumn>
            <telerik:GridButtonColumn CommandName="Delete" UniqueName="DeleteColumn"         ButtonType="ImageButton"
                Text="UsuÅ„">
                <HeaderStyle Width="3%" />
            </telerik:GridButtonColumn>
            <telerik:GridBoundColumn DataField="Nazwa" HeaderText="Nazwa przedmiotu" UniqueName="Nazwa"
                FilterControlAltText="Filter Nazwa column" DataType="System.String" SortExpression="Nazwa"
                ReadOnly="true">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Kod" HeaderText="Kod" UniqueName="Kod" FilterControlAltText="Filter Kod column"
                DataType="System.String" SortExpression="Kod" ReadOnly="true">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="IdKatedra" HeaderText="IdKatedra" UniqueName="IdKatedra"
                FilterControlAltText="Filter IdKatedra column" DataType="System.Int32" ReadOnly="true"
                Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="KatedraNazwa" HeaderText="Katedra" UniqueName="Katedra"
                FilterControlAltText="Filter Katedra column" DataType="System.String" SortExpression="Katedra"
                ReadOnly="true">
            </telerik:GridBoundColumn>
        </Columns>
        <EditFormSettings EditFormType="WebUserControl" UserControlName="PrzedmiotyKatedre.ascx">
            <EditColumn FilterControlAltText="Filter EditCommandColumn column" ButtonType="ImageButton">
            </EditColumn>
        </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>

Second RadGrid with SqlDataSource:

<asp:SqlDataSource ID="SqlDataSourcePrzedmiotyWydzialuBrakKatedry" runat="server"
                        ConnectionString="<%$ ConnectionStrings:DefaultDatabaseConnection %>" SelectCommand="katw_Przedmioty_Wydzialu_BrakKatedry_sel"
                        SelectCommandType="StoredProcedure">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="WydzialRadComboBox" Name="IdWydzial" PropertyName="SelectedValue"
                                Type="Int32" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
                    </telerik:RadAjaxLoadingPanel>
                    <telerik:RadGrid ID="RadGridPrzedmiotyWydzialuBrakKatedry" runat="server" AllowPaging="true"
                        AutoGenerateColumns="false" CellSpacing="0" Culture="pl-PL" DataSourceID="SqlDataSourcePrzedmiotyWydzialuBrakKatedry"
                        GridLines="None" HorizontalAlign="Justify" Skin="Simple">
                        <ClientSettings>
                            <Selecting CellSelectionMode="None" />
                        </ClientSettings>
                        <MasterTableView DataSourceID="SqlDataSourcePrzedmiotyWydzialuBrakKatedry" NoMasterRecordsText="Brak rekordów do wyÅ›wietlenia."
                            DataKeyNames="IdPrzedmiot" CommandItemDisplay="Top">
                            <CommandItemSettings ExportToPdfText="Export to PDF" RefreshText="OdÅ›wież" ShowAddNewRecordButton="False" />
                            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                <HeaderStyle Width="20px" />
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                <HeaderStyle Width="20px" />
                            </ExpandCollapseColumn>
                            <Columns>
                                <telerik:GridBoundColumn DataField="IdPrzedmiot" HeaderText="IdPrzedmiot" UniqueName="IdPrzedmiot"
                                    FilterControlAltText="Filter IdPrzedmiot column" DataType="System.Int32" SortExpression="IdPrzedmiot"
                                    ReadOnly="true" Visible="false">
                                </telerik:GridBoundColumn>
                                <telerik:GridButtonColumn CommandName="Edit" Text="Edytuj" UniqueName="EditColumn"
                                    ButtonType="ImageButton">
                                    <HeaderStyle Width="3%" />
                                </telerik:GridButtonColumn>
                                <telerik:GridBoundColumn DataField="Nazwa" HeaderText="Nazwa przedmiotu" UniqueName="Nazwa"
                                    FilterControlAltText="Filter Nazwa column" DataType="System.String" SortExpression="Nazwa"
                                    ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="Kod" HeaderText="Kod" UniqueName="Kod" FilterControlAltText="Filter Kod column"
                                    DataType="System.String" SortExpression="Kod" ReadOnly="true">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="IdKatedra" HeaderText="IdKatedra" UniqueName="IdKatedra"
                                    FilterControlAltText="Filter IdKatedra column" DataType="System.Int32" ReadOnly="true"
                                    Visible="false">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="KatedraNazwa" HeaderText="Katedra" UniqueName="Katedra"
                                    FilterControlAltText="Filter Katedra column" DataType="System.String" SortExpression="Katedra"
                                    ReadOnly="true">
                                </telerik:GridBoundColumn>
                            </Columns>
                            <EditFormSettings EditFormType="WebUserControl" UserControlName="PrzedmiotyKatedre.ascx">
                                <EditColumn FilterControlAltText="Filter EditCommandColumn column" ButtonType="ImageButton">
                                </EditColumn>
                            </EditFormSettings>
                        </MasterTableView>
                    </telerik:RadGrid>

2 Answers, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 07 Jun 2012, 03:45 PM
Hello Michal,

You will need to add RadGridPrzedmiotyWydzialuBrakKatedry as an updated control in the Ajax manager settings in order to enable its response to a callback raised from RadGridPrzedmiotyWydzialu:
<AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGridPrzedmiotyWydzialu">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGridPrzedmiotyWydzialuBrakKatedry" LoadingPanelID="RadAjaxLoadingPanel" />
           ...

That should solve the issue. Give it a try and let me know about the result.

Kind regards,
Eyup
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Michal
Top achievements
Rank 1
answered on 14 Jun 2012, 06:56 PM
Hey Eyup,  

thank you so much for your help. I did as you said and it works.

Best regards,
Michal
Tags
Grid
Asked by
Michal
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Michal
Top achievements
Rank 1
Share this question
or