Fill UniGrid with data from external web service

Lubomir Zigo asked on September 23, 2015 14:19

Hi, I need to fill UniGrid with data received from external web service as DataSet (using Web reference). I set myUniGrid.DataSource = myDataSet, but no data displayed. What else should I do to display DataSet in UniGrid. I can provide my code if neccesary.

Correct Answer

Maarten van den Hooven answered on September 23, 2015 21:19

Hi Lubomir,

I looked in my code and delete all obsolute code and it is working for me. This is the code of my custom webpart, hopefully you can see what is different with your code:

UniGrid.ascx

<%@ Register src="~/CMSAdminControls/UI/UniGrid/UniGrid.ascx" TagName="UniGrid" TagPrefix="cms" %>
<%@ Register Namespace="CMS.UIControls.UniGridConfig" TagPrefix="ug" Assembly="CMS.UIControls" %>   
<cms:UniGrid runat="server" ID="UniGrid" IsLiveSite="true">
    <GridColumns>
        <ug:Column Source="DocumentName" Caption="Document name" Wrap="false" />
        <ug:Column Source="DocumentDescription" Caption="Description" Wrap="false" />
    </GridColumns>
</cms:UniGrid>

UniGrid.ascx.cs

 /// <summary>
/// Initializes the control properties.
/// </summary>
protected void SetupControl()
{
    if (StopProcessing)
    {
        // Do not process
    }
    else
    {
    }
}
/// <summary>
/// Loads and setups web part.
/// </summary>
protected override void OnLoad(EventArgs e)
{
    // Load the grid data
    ReloadGrid();
    base.OnLoad(e);
}
/// <summary>
/// Reloads the grid with given page index.
/// </summary>
protected void ReloadGrid()
{
    // Reload data
    if (this.DataSourceControl != null && DataSourceControl.DataSource != null && !binded)
    {
        System.Data.DataSet ds = new System.Data.DataSet();
        ds.Tables.Add(((System.Data.DataView)DataSourceControl.DataSource).ToTable());
        UniGrid.DataSource = ds;
        UniGrid.DataBind();
        UniGrid.ReloadData();
    }
}

Good luck with debugging your UniGrid!!!!

If this answer helped you, please vote for my answer :-)

0 votesVote for this answer Unmark Correct answer

Recent Answers


Maarten van den Hooven answered on September 23, 2015 14:43

Hi Lubormir,

An UniGrid in Kentico API inherits from GridView in ASP.NET so look at this article on StackOverflow : How to bind with GridView or this article how to a DataBind of your Dataset on MSDN : GridView.DataBind Method

You can also have an look at the Kentico UniGrid documentation

Good luck and if you have any problems let us know with some code examples.

If this answer helped you, please vote for my answer :-)

0 votesVote for this answer Mark as a Correct answer

Lubomir Zigo answered on September 23, 2015 14:57 (last edited on September 23, 2015 15:03)

I tried myUniGrid.DataBind() and also myUniGrid.ReloadData() and UniGrid is still empty. I placed ASP GridView on same page and it has data.

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 23, 2015 15:14 (last edited on September 23, 2015 15:30)

Hi Lubomir, It seems that you are doing it correctly, maybe it is the problem of when you assign the datasource. An example of an custom UniGrid webpart I build is this :

/// <summary>
/// Loads and setups web part.
/// </summary>
protected override void OnLoad(EventArgs e)
{
    // Load the grid data
    ReloadGrid();

    base.OnLoad(e);
}

/// <summary>
/// Reloads the grid with given page index.
/// </summary>
protected void ReloadGrid()
{
    // Reload data
    if (this.DataSourceControl != null && DataSourceControl.DataSource != null && !binded)
    {
        System.Data.DataSet ds = new System.Data.DataSet();
        ds.Tables.Add(((System.Data.DataView)DataSourceControl.DataSource).ToTable());

        UniGrid.DataSource = ds;
        UniGrid.OrderBy = this.DataSourceControl.OrderBy;
        UniGrid.ReloadData();
    }
}

I use an DataSource webpart on my page to fill the DataSource, but that cannot be the problem. Het is also Advanced UniGrid example on Kentico.

0 votesVote for this answer Mark as a Correct answer

Lubomir Zigo answered on September 23, 2015 15:26 (last edited on September 23, 2015 15:30)

My code is here, looks like yours.

protected override void OnLoad(EventArgs e)
{
    this.GetMyData();
    base.OnLoad(e);
}

private void GetMyData()
{
    try
    {
        this.InnerGrid.DataSource = null;

        if (this.UniGridId > 0)
        {
            MyWs.MyWs proxy = new MyWs.MyWs();
            DataSet dataSet = proxy.GetDataSetForUniGrid(this.UniGridId, this.UserId);

            // This is UniGrid and is empty
            this.InnerGrid.DataSource = dataSet;
            this.InnerGrid.DataBind();
            this.InnerGrid.ReloadData();

            // This ASP GridView and has data
            this.InnerGridAsp.DataSource = dataSet;
            this.InnerGridAsp.DataBind();

            // This show number of records in UniGrid and is > 0 (VERY WEIRD ???)
            this.InnerLabel.Text = "Rows: " + this.InnerGrid.RowsCount.ToString();
        }
        else
        {
            this.InnerGrid.DataSource = null;
            this.InnerGrid.ReloadData();
        }
    }
    catch (Exception ex)
    {
        this.InnerLabel.Text = ex.ToString();
    }
}
0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 23, 2015 16:53

@Lubomir there is no need to call the ReloadData() immediately after you call DataBind(). Do you have a column definition setup for your UniGrid? Have you debugged to see if your UniGrid has data in the dataset after it is bound? What other steps have you taken to debug the issue?

0 votesVote for this answer Mark as a Correct answer

Maarten van den Hooven answered on September 23, 2015 17:04 (last edited on September 23, 2015 17:16)

Hi Lubomir, try to remove the DataBind() and only call the ReloadData().

If that is not working I will try it later this night on in my application.

0 votesVote for this answer Mark as a Correct answer

Lubomir Zigo answered on September 24, 2015 09:11

@Maarten, thank you.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.