RadGrid does not populate

6 posts, 0 answers
  1. Anup
    Anup avatar
    11 posts
    Member since:
    Feb 2012

    Posted 14 Feb 2012 Link to this post

    Hi,
    I am using 2 Stored Procedures to populate 2 different RadGrids. For RadGrid1, OnNeedDataSource event calls a handler function inside which a SP is executed and the data table is equated to RadGrid1.DataSource. Now, I want to populate RadGrid2 when a row is selected in RadGrid1. For this, OnRowSelected event of RadGrid1 is handled by a Javascript function that is extracting some specific cell values of the selected row and initiates an ajaxRequest() with argument string passed. I am using a RadAjaxManager which looks like :

    <

    telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_OnAjaxRequest">

     <AjaxSettings>

     <telerik:AjaxSetting AjaxControlID="RadGrid1">

     <UpdatedControls>

     <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />

     

    <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel1" />

     </UpdatedControls>

     </telerik:AjaxSetting>

     </AjaxSettings>

     </telerik:RadAjaxManager>

     
    In Code-Behind, I have a handler function RadAjaxManager1_OnAjaxRequest() for handling the ajax request. Inside RadAjaxManager1_OnAjaxRequest, I am passing on the arguments to execute an SP and equating the data table returned to RadGrid2.DataSource, as below :

    protected

     

    void RadAjaxManager1_OnAjaxRequest(object sender, AjaxRequestEventArgs e)

    {

    String argument = e.Argument;

    String[] args = argument.Split("^".ToCharArray());

    NameValueCollection parameters = new NameValueCollection();

    parameters.Add("@par1", args[0]);

     parameters.Add("@par2", args[1]);

     parameters.Add("@par3", args[2]);

     RadGrid2.DataSource = obj.ExecuteSP("MySP", parameters);

     RadGrid2.Rebind();
    }

    The problem arises now, when I select a row in RadGrid1, I do not see any RadAjaxLoadingPanel being loaded. Moreover, the RadGrid2 does not populate. However, While debugging I am able to see that the rows are being returned(RadGrid2.DataSource.Rows.Count is greater than 0).

    Thanks,
    Anup

  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 14 Feb 2012 Link to this post

    Hi Anup,

    It is the RadAjaxManager control that makes the ajax request - so RadAjaxManager should ajaxify the second grid. In other words, you need to following ajax setting:

    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
        <UpdatedControls>
            <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="rAjaxLoadingPanel"/>
        </UpdatedControls>
    </telerik:AjaxSetting>

    Hope it helps.
     
    All the best,
    Tsvetoslav
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. Anup
    Anup avatar
    11 posts
    Member since:
    Feb 2012

    Posted 14 Feb 2012 Link to this post

    Hi Tsvetoslav,

    Thanks alot. This worked :)
    But now, after the RadGrid2 gets populated, the selected row in RadGrid1 gets deselected automatically.

    How to stop this automatic deselection?

    Thanks...
  4. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 17 Feb 2012 Link to this post

    Hi Anup,

    RadGrid does not automatically persist the selected state of its items. You need to do so programmatically as explained in the followign help topics:
    http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-on-sorting.html
    http://www.telerik.com/help/aspnet-ajax/grid-persist-selected-rows-client-sorting-paging-grouping-filtering.html


    Greetings, Tsvetoslav
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  5. Anup
    Anup avatar
    11 posts
    Member since:
    Feb 2012

    Posted 17 Feb 2012 Link to this post

    Thanks Tsvetoslav,
    I did try the steps described in these links earlier but ended up in another issue. I was able to restore the current selection but, RadGrid also persisted the last selection. I tried hard but could not resolve it.

    Finally, I decided to put the code to execute SP and  equate it to RadGrid2 .DataSource in the OnSelectedIndexChanged event of RadGrid1 :)

    Do let me know if this is a correct implementation.
    Thanks again!!!
  6. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 17 Feb 2012 Link to this post

    Hi Anup,

    Yes, it is correct. You just need one more step - to call RadGrid2's Rebind() method.

    However, if you are using NeedDataSource for RadGrid2, the correct approach will be:

    - in the SelectedIndexChanged event for RadGrid1, extract and keep in local variables any information you need for the population of RadGrid2; then call RadGrid2's Rebind() method.

    - in the NeedDataSource event for RadGrid2, use the information kept from step1 to correctly call the stored procedure.
     
    Greetings,
    Tsvetoslav
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top