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

refreshing a grid

10 Answers 118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mww
Top achievements
Rank 1
mww asked on 20 Oct 2008, 04:02 PM
I have a grid and a RADCombo on a page.  The grid has its datasource mapped to a custom object.  When a user makes a selection in the drop down, I have some code that deletes all the underlying data displayed in the grid.  The data deletion is performed in the Itemsrequested event of the drop down

Ive traced through the code and this works ok, the problem is that the grid is never refreshed, the HTML stays the same even though there are now no rows to display.  In my code that does the deletion I've used Rebind() which I thought woud work.

private void DeleteSubCategories()  
        {  
            int id = -1;  
            string res = string.Empty;  
            bool ok = Int32.TryParse(this.HiddenArtistID.Value, out id);  
            if (ok)  
            {  
                res = categorymanager.DeleteAllSecondaryCategories(id);  
                if (!string.IsNullOrEmpty(res))  
                {  
                    RadGridSecondaryCategories.Controls.Add(new LiteralControl("Unable to delete secondary categories. Reason: " + res));  
                      
                }  
                RadGridSecondaryCategories.Rebind();  
                  
                  
            }  
        } 

The rebind does cause the NeedDataSource event to fire and no data is returned, so I how do I get the grid to refresh and show no rows ?

I have used a RADAJAX manager and added the grid to it in the PageLoad event

_RADAJAXManager = (Telerik.Web.UI.RadAjaxManager)Master.FindControl("RadAjaxManager1");  
            if (_RADAJAXManager != null)  
            {  
                _RADAJAXManager.AjaxSettings.AddAjaxSetting(this.RadGridSecondaryCategories, this.RadGridSecondaryCategories, this.RadAjaxLoadingPanel1);  
                  
            } 

 

10 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 22 Oct 2008, 08:04 AM
Hello mark,

You need to add new setting where you can set the combo as initiator and the grid as update control.

Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
mww
Top achievements
Rank 1
answered on 22 Oct 2008, 08:56 AM
how do I do that ?
0
Vlad
Telerik team
answered on 22 Oct 2008, 09:19 AM
mark,

You already have similar code! Please look at your first post.

Regards,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
mww
Top achievements
Rank 1
answered on 22 Oct 2008, 09:21 AM
If you mean using a RADAjaxManagerProxy, Ive set it up as follows

<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="RadComboBoxType"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGridSecondaryCategories" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="RadComboBoxArtistGenre"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGridSecondaryCategories" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="RadGridSecondaryCategories"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGridSecondaryCategories"  
                    LoadingPanelID="RadAjaxLoadingPanel1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManagerProxy> 

But it makes no difference, the data is always deleted as designed but the grid is never refreshed.  If I click the refresh button on the command bar, then the grid gets emptied, but I want this to happen automatically
0
Vlad
Telerik team
answered on 22 Oct 2008, 09:26 AM
Hello mark,

How your serve-side method DeleteSubCategories() is executed? Do you have AutoPostBack for the combo?

Best wishes,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
mww
Top achievements
Rank 1
answered on 22 Oct 2008, 09:41 AM
DeleteSubCategories is executed in the Itemsrequested of the two combos

<telerik:RadComboBox ID="RadComboBoxType" Runat="server" OnClientSelectedIndexChanging="LoadGenres" 
                        onitemsrequested="RadComboBoxType_ItemsRequested" Skin="Web20"   
                        Width="250px"
                        <CollapseAnimation Duration="200" Type="OutQuint" /> 
             </telerik:RadComboBox> 
             <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"  
                            ControlToValidate="RadComboBoxType" ErrorMessage="*" Font-Bold="True"  
                            InitialValue="-- Select A Type --" ValidationGroup="ArtistValidation"></asp:RequiredFieldValidator> 
                </div> 
                <div class="cellArtistControl"
                    <telerik:RadComboBox ID="RadComboBoxArtistGenre" Runat="server" OnClientSelectedIndexChanging="LoadCategories"  
                    OnClientItemsRequested="ItemsLoaded" Skin="Web20"   
                    Width="250px" onitemsrequested="RadComboBoxArtistGenre_ItemsRequested"  
                        EnableLoadOnDemand="true" > 
                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
             </telerik:RadComboBox> 

Im using loadonDemand so that the item selected in the 'Type' combo is used as a filter for items displayed in the 'Genre' combo

Tracing though the code shows the deletion is happening.  Ive tried both Rebind and RaisePostBackEvent on the grid in the deletion method, but neither makes any difference.

Is there something fundamentally wrong with the way Im trying to achive this functionality ?
0
mww
Top achievements
Rank 1
answered on 22 Oct 2008, 10:42 AM
Ive run out of options now guys.

I put a 'dummy' combo box on the page and added 2 items.  I added this to the RADAJaxProxyManager.   Selecting an item in this dropdown still didnt cause an ajax postback so the grid didnt refresh.  I set the postback property to 'true' and this made no difference.  I even added the panel that the grid is inside to the ajax proxy manager, this made no difference

<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="RadComboBoxTest"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGridSecondaryCategories" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="RadComboBoxType"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGridSecondaryCategories" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="RadComboBoxArtistGenre"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGridSecondaryCategories" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="RadGridSecondaryCategories"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadGridSecondaryCategories"  
                    LoadingPanelID="RadAjaxLoadingPanel1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManagerProxy> 


How Can I force an ajax postback for the grid in the codebehind ?
I can see the functioanlity working when I hit the refresh button, the NeedDataSource event is fired and the program logic returns a custom collection object with no items in it and sets it as the grid datasource, but the actual grid contents stay the same.
0
Daniel
Telerik team
answered on 22 Oct 2008, 12:01 PM
Hello Mark,

Please try AutoPostBack property as suggested by Vlad.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
mww
Top achievements
Rank 1
answered on 22 Oct 2008, 12:19 PM
please read the text of my last message, especially the part where it says

'I set the postback property to 'true' and this made no difference.'
0
Daniel
Telerik team
answered on 23 Oct 2008, 12:25 PM
Hello Mark,

Please excuse me for the inadvertence.

For the convenience of our community I present your solution here.

javascript:
function ItemsLoaded(combo, eventarqs) 
    refreshGrid(null); 
    if (combo.get_items().get_count() > 0) 
    { 
        combo.set_text(combo.get_items().getItem(0).get_text()); 
        combo.get_items().getItem(0).highlight(); 
        combo.showDropDown(); 
    } 
    else 
    { 
        combo.set_text(" "); 
        combo.clearItems(); 
    } 
 
function refreshGrid(arg) 
    var masterTableView = $find("<%= RadGridSecondaryCategories.ClientID %>").get_masterTableView(); 
    if (masterTableView.get_dataItems().length > 0) 
        $find("<%= Telerik.Web.UI.RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("SubCategoryRebind"); 
}  

codebehind (c#)
protected void Page_Load(object sender, EventArgs e) 
    RadAjaxManager manager = RadAjaxManager.GetCurrent(Page); 
    manager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(RadAjaxManagerProxy1_AjaxRequest);  



protected void RadAjaxManagerProxy1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e) 
    switch (e.Argument) 
    { 
        case "SubCategoryRebind"
            this.RadGridSecondaryCategories.Rebind(); 
            break
    } 
}  

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
mww
Top achievements
Rank 1
Answers by
Vlad
Telerik team
mww
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or