ajax call for field in grid

11 posts, 0 answers
  1. sircutbreaker
    sircutbreaker avatar
    111 posts
    Member since:
    Oct 2007

    Posted 31 May 2008 Link to this post

    I have an asp.net application that produces a grid... one of the items in the grid is a link to "view docs".. if this link is pressed.. a process is fired off where asp.net calls out to SAP and takes you to another page and if there are docs available, puts them in a grid.. My clients do not want "view docs" to appear unless there are actual docs to view..

    If i made the call for each item in the grid to sap to determinw this,  it would take a very long time to load... how can i make the call in ajax so that the grid loads normally and then goes down the list of items and makes an asynchronous call to get the "view docs" data...if there is no data, i would of course leave the link not visible...

    I would make the column a template... put an ajax panel with a hyperlink... but then how would i make the call so that it wouldn't tie up the grid and let the rest it load?

    any help would be appreciated...


    Jeff
  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 02 Jun 2008 Link to this post

    Hi sircutbreaker,

    If you do not want to call expensive operations in the item events of RadGrid (ItemCreated and ItemDataBound), you can call them in Page_Init before you start initializing your grid, load return values to variables (or arrays in case of many) and then in ItemDataBound check for the respective value of the variable and set the link visibility to false. In any case, the rendering of the grid on the browser is done after any manipulations with its items, so you will need to finish the operation before RadGrid is loaded.

    See if this works for you.

    Best wishes,
    Veli
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. sircutbreaker
    sircutbreaker avatar
    111 posts
    Member since:
    Oct 2007

    Posted 02 Jun 2008 Link to this post

    I was actually thinking the opposite... I want to populate the grid... and then after the grid is rendered... start looping through it and calling out to SAP... and if the correct value comes back, make the link visible...

    i dont care if it takes a while to do AFTER the grid is rendered...

    I would prefer to see a loading panel where the link is... until something comes back..

    this is the preferred behavior.

    How to make the asynchronous call is my question...


    Thanks and regards,

    Jeff
  5. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 03 Jun 2008 Link to this post

    Hi sircutbreaker,

    Thank you for the additional explanation.

    You can loop through the items in the grid intercepting the DataBound or PreRender event of the control to perform some custom operation if needed.

    In order to display the grid after the entire set of data is passed from the server and the control is rendered completely, consider ajaxifying the grid instance via RadAjaxManager/RadAjaxPanel and display a loading panel while the data is still processed. Review the documentation article linked below for further details:

    http://www.telerik.com/help/aspnet-ajax/ajxshowloadingpaneloninitialpageload.html

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. sircutbreaker
    sircutbreaker avatar
    111 posts
    Member since:
    Oct 2007

    Posted 03 Jun 2008 Link to this post

    Closer.. but not quite..

    I have a grid that populates... and as it stands right now, the "view docs" link is the last item in the row...

    if you press the link.. (as it is now) it will redirect to another page that makes a call out to SAP and combines a bunch of items and sometimes comes back with a link to a tif file or an array of them...

    ok...

    I want the grid to populate just like it does.. but i want that "view docs" link to be in an ajax panel.. so the loading gif would be displayed... (in other words, there would be a whole column of loading gifs... when the grid initially loads)
    then.. i want to loop through the grid and make the call to SAP (via ajax)... if something comes back, i would make the view docs link active.. and take them another page that would display the link or links to the scanned (IXOS) documents.
    If the array comes back empty, i would just leave the field empty or put an "n./a" there...

    so the user would see the grid come up.. with all the data except for the "view docs" where they would see the loading gifs... and then... one by one.. as the call is made out to SAP, the loading gifs would be replaced by a link or an n/a.

    I dont want to wait for all the data to come back as it would take a long time... SAP can be slow... especially when the servers reside halfway around the world...

    having each piece of data come back...asynchronously is what i am trying to accomplish here..

    I hope this helps to explain my quest here..

    :)

    Jeff
  7. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 04 Jun 2008 Link to this post

    Hi sircutbreaker,

    Unfortunately I do not think that the exact functionality you are searching for can be achieved. As a workaround you may consider making the loading panel sticky (setting its IsSticky property to true and positioning it at the desired location on the page) and displaying the ViewDocs links after the entire grid is loaded and rendered. I hope this is feasible solution for your situation.
     
    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. sircutbreaker
    sircutbreaker avatar
    111 posts
    Member since:
    Oct 2007

    Posted 04 Jun 2008 Link to this post

    Maybe i am explaining this wrong... I dont really care about the loading panel... The main thing is that i can display the grid (which is a list of engine parts that match a part number that the client enters...)

    i just want to call a function that retrieves some data... and i dont want the client to have to wait for that data to come back... i want to make the call via ajax...  and i dont know how.

    in other words.. i want to load and render the grid...

    and then AFTER the grid is rendered i would like to call another routine that loops through the grid..makes the call to SAP, and updates the grid row by row...

    does this make sense?

    jeff

  9. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 04 Jun 2008 Link to this post

    Hello sircutbreaker,

    Thank you for the additional explanation. In this case you can consider intercepting the PreRender event of RadGrid (when the data will be available on server) and invoke your routine which iterates through the grid records and updates them one by one. Finally, invoke the Rebind() method of the control to reflect the changes.

    Alternatively, wire the OnGridCreated client event (when the grid object will be initialized on the client) and perform an ajax request via the ajaxRequest(eventSrc, eventArgs) method of RadAjaxManager (provided that you ajaxified the grid with ajax manager). Then inside the AjaxRequest handler update the grid data and once again call the Rebind() method to refresh it.

    I hope these directions are helpful.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  10. sircutbreaker
    sircutbreaker avatar
    111 posts
    Member since:
    Oct 2007

    Posted 05 Jun 2008 Link to this post

    Ok.. I set up a live example...   http://sircutbreaker.com

    I appreciate any insight to this...

    Same scenario... I load up the grid... I set the "View" linkbutton .visible=false

    Now, how would i make a call to the ValidateDocuments(); which would determine whether to make the linkbutton visible or not...

    and secondly, since the linkbutton is in an ajax panel, how to i make it hit the itemcommand routine... (if it is visible and you press it, it never gets there until the page is refreshed)

    Thanks for your help...

    Jeff

    Here is the .aspx:

    <%

    @ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="sb.Website._Default" %>

    <%

    @ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

    <!

    DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <

    html xmlns="http://www.w3.org/1999/xhtml">

    <

    head runat="server">

    <title>Home Page</title>

    </

    head>

    <

    body>

    <form id="form1" runat="server">

    <div>

    <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">

    </telerik:RadScriptManager>

    <br />

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"

    AutoGenerateColumns="False" GridLines="None"

    onneeddatasource="RadGrid1_NeedDataSource" Skin="Vista"

    onitemcommand="RadGrid1_ItemCommand" onitemcreated="RadGrid1_ItemCreated">

    <

    MasterTableView datakeynames="TestID">

    <

    RowIndicatorColumn Visible="False">

    <

    HeaderStyle Width="20px"></HeaderStyle>

    </

    RowIndicatorColumn>

    <

    ExpandCollapseColumn Visible="False" Resizable="False">

    <

    HeaderStyle Width="20px"></HeaderStyle>

    </

    ExpandCollapseColumn>

    <Columns>

    <telerik:GridBoundColumn DataField="TestID" DataType="System.Int32"

    HeaderText="TestID" ReadOnly="True" SortExpression="TestID" UniqueName="TestID">

    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn DataField="MODULE" HeaderText="MODULE"

    SortExpression="MODULE" UniqueName="MODULE">

    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn DataField="STAGE" HeaderText="STAGE"

    SortExpression="STAGE" UniqueName="STAGE">

    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn DataField="PART" HeaderText="PART"

    SortExpression="PART" UniqueName="PART">

    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn DataField="SN" HeaderText="SN" SortExpression="SN"

    UniqueName="SN">

    </telerik:GridBoundColumn>

    <telerik:GridBoundColumn DataField="Docs" HeaderText="Docs"

    SortExpression="Docs" UniqueName="Docs" Visible="False">

    </telerik:GridBoundColumn>

    <telerik:GridTemplateColumn UniqueName="TemplateColumn">

    <EditItemTemplate>

    <asp:LinkButton runat="server" CommandName="Update" Text="Update"></asp:LinkButton>

    &nbsp;<asp:LinkButton runat="server" CausesValidation="false" CommandName="Cancel"

    Text="Cancel"></asp:LinkButton>

    </EditItemTemplate>

    <ItemTemplate>

    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">

    <asp:LinkButton ID="btnView" runat="server" CausesValidation="false"

    CommandName="View" Text="View"></asp:LinkButton>

    </telerik:RadAjaxPanel>

    </ItemTemplate>

    </telerik:GridTemplateColumn>

    </Columns>

    <

    EditFormSettings>

    <

    PopUpSettings ScrollBars="None"></PopUpSettings>

    </

    EditFormSettings>

    </

    MasterTableView>

    </telerik:RadGrid>

    </div>

    </form>

    </

    body>

    </

    html>



    Here is the Code Behind:

    #region

    Using Directives

    using

    System;

    using

    System.Data;

    using

    System.Collections;

    using

    System.Configuration;

    using

    System.Web;

    using

    System.Web.Security;

    using

    System.Web.UI;

    using

    System.Web.UI.WebControls;

    using

    System.Web.UI.WebControls.WebParts;

    using

    System.Web.UI.HtmlControls;

    using

    sb.Data;

    using

    sb.Entities;

    using

    sb.Service;

    using

    Telerik.Web.UI;

    #endregion

    namespace

    sb.Website

    {

    public partial class _Default : System.Web.UI.Page

    {

    /// <summary>

    /// Handles the Load event of the Page class.

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)

    {

    RadGrid1.DataSource =

    DataRepository.TestProvider.GetAll();

    }

     

    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)

    {

    if (e.Item is GridDataItem)

    {

    GridDataItem item = (GridDataItem)e.Item;

    LinkButton lb = new LinkButton();

    lb = (

    LinkButton)item["TemplateColumn"].FindControl("btnView");

    lb.Visible =

    false;

    }

    }

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)

    {

    if (e.CommandName == "View")

    {

    //redirect user

    }

    }

    protected bool ValidateDocuments()

    {

    bool docs = false;

    //call to sap...

    //get back an array...

    //if array is empty.. bool = false;

    //if array is not empty... bool = true;

    return docs;

    }

    }

    }

  11. sircutbreaker
    sircutbreaker avatar
    111 posts
    Member since:
    Oct 2007

    Posted 05 Jun 2008 Link to this post

    I can make the call when collecting the data, but it just takes too long to render the grid in that instance.
  12. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 06 Jun 2008 Link to this post

    Hi sircutbreaker,

    I think that the best option for you might be to determine whether the view button inside the item template would be inside the ItemDataBound handler of the grid as shown here:

    http://www.telerik.com/help/aspnet-ajax/grdconditionalimagedisplayingridcolumn.html

    This will save you another iteration to traverse all grid items after they are loaded.

    Additionally, if you want to ajaxify only a particular controls inside the grid, consider the solution presented in this KB article on our site which gives you greater flexibility:

    http://www.telerik.com/support/kb/article/b454K-ted-b454T-ceh-b454c-ceh.aspx

    Alternatively, you can ajaxify the entire grid instance through the ajax manager settings if you prefer. I hope that these directions will help you attain the functionality you are searching for.

    Best regards,
    Stephen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017