UniSelector UniGrid OnExternalDataBound

Delford Chaffin asked on January 6, 2016 15:33

I have the following UniSelector on a page:

<cms:UniSelector ID="usProducts" runat="server" ObjectType="ecommerce.sku" SelectionMode="Multiple" />

... defined by this XML:

<?xml version="1.0" encoding="utf-8" ?>
<grid> 
  <columns>
    <column source="##ALL##" externalsourcename="Select" wrap="false" text-align="center" />
    <column source="SKUNumber" caption="SKU Number" wrap="false" localize="false" />
    <column source="SKUID" caption="SKU Name" wrap="false" externalsourcename="Product" />
  </columns>
  <options>
    <key name="DisplayFilter" value="false" />
  </options>
</grid>

In the C#, I have:

protected void Page_Load(object sender, EventArgs e)
{
    usProducts.UniGrid.OnExternalDataBound += UniGrid_OnExternalDataBound;
}

protected object UniGrid_OnExternalDataBound(object sender, string sourceName, object parameter)
{
    switch (sourceName.ToLowerCSafe())
    {
        case "product":
            {
                string _skuID = ValidationHelper.GetString(parameter, "");
                if (String.IsNullOrEmpty(_skuID)) { return null; }
                string product = "";
                foreach (DataRow r in naProducts.Rows)
                {
                    if (r["NodeSKUID"].ToString() == _skuID)
                    {
                        product = r["ProductDisplayName"].ToString();
                        if (String.IsNullOrEmpty(product))
                        {
                            product = r["ProductName"].ToString();
                        }
                    }
                }
                product = product.Replace("<br />", " - ");
                return product;
            }
    }
    return null;
}

I can Response.Write(product) right there before "return product;" and see that it has the right value, but the UniGrid on the page never shows the output in that column - it is blank.

Code very similar to this works on another page with just a UniGrid, but this doesn't seem to work on this UniSelector's UniGrid. What am I missing?

Thanks!

Recent Answers


David te Kloese answered on January 6, 2016 15:47

Hi,

Have you tried a ReloadData() on your grid?

David

0 votesVote for this answer Mark as a Correct answer

Delford Chaffin answered on January 6, 2016 15:50

I had not, but I added:

usProducts.UniGrid.ReloadData();

... to the end of my Page_Load event and it didn't help.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on January 6, 2016 16:27

Hi,

can you try adding it before the return of the UniGrid_OnExternalDataBound.

David

0 votesVote for this answer Mark as a Correct answer

Delford Chaffin answered on January 6, 2016 16:32

Yeah, that performed about as I expected (i.e. created an infinite loop).

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 6, 2016 17:45

Is this in a webpart or on a page template? If in a webpart, assign your OnExternalDataBound event to the grid in the OnContentLoaded event.

0 votesVote for this answer Mark as a Correct answer

Delford Chaffin answered on January 6, 2016 20:38

This is in a User Control. Here is the whole contents of the .ascx page:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="NatAltDealerProducts.ascx.cs" Inherits="nla_custom_NatAltDealerProducts" %>
<%@ Register src="~/CMSAdminControls/UI/UniSelector/UniSelector.ascx" tagname="UniSelector" tagprefix="cms" %>

<cms:UniSelector ID="usProducts" runat="server" ObjectType="ecommerce.sku" SelectionMode="Multiple" />

I tried to move the event binding to the Page_Unload event to no avail. The .ascx.cs page includes the event handler above, a couple properties and a Page_Load event that sets up the UniSelector as such:

usProducts.WhereCondition = "SKUSiteID = 2 AND SKUEnabled = 1 AND SKUOptionCategoryID IS NULL";
usProducts.OrderBy = "SKUName ASC";
usProducts.ReturnColumnName = "SKUID";
usProducts.DynamicColumnName = true;
usProducts.GridName = "~/nla/custom/NatAltProductGrid.xml";
usProducts.AdditionalColumns = "SKUName,SKUNumber";
usProducts.SelectItemPageUrl = "~/nla/custom/NatAltDealerProductSelectionDialog.aspx";
usProducts.UniGrid.OnExternalDataBound += UniGrid_OnExternalDataBound;
0 votesVote for this answer Mark as a Correct answer

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