Get Property From TreeNode

Chris Hinds asked on August 24, 2015 13:01

I have a method that returns a sinlge property as a treenodedataset. It uses the TreeHelper to do this. So in a method called GetSizesFromMasterSKU, I have

var result = TreeHelper.GetDocuments(siteName, siteFolder, culture, combine, "cms.product", string.Format("(Size IS NOT NULL AND Size != '') AND SkuNumber = '{0}'", sku), "", -1, true, -1, "DISTINCT Size");

From the results I can iterate over them and add them to a drop down list. So in the code behind file I have:

var sizes = Utils.GetSizesFromMasterSKU(CMSContext.CurrentSiteName, siteFolder, CultureHelper.GetDefaultCulture(CMSContext.CurrentSiteName), CurrentSite.CombineWithDefaultCulture, masterSku);

DropDownList sizeVariants = (DropDownList)item.FindControl("sizeVariants");

sizeVariants.DataSource = sizes;

and in the ascx file I have:

<asp:DropDownList ID="sizeVariants" runat="server" CausesValidation="false" AutoPostBack="true" CssClass="chzn-select" DataTextField="Size" DataValueField="Size" ValidationGroup="AddToBasket" Visible="false" />

which works fine. What I want to do however it to retrieve the value in code but I can't seem to retrieve it from the results of the call to the TreeHelper.

var test = sizes["Size"]

returns a null. How do I get the property returned from the TreeHelper?

Correct Answer

Suneel Jhangiani answered on August 24, 2015 15:36

In that case you would need to parse the DataSet that is returned.

foreach (DataRow row in sizes.Tables[0].Rows)
{
    var test = row["Size"];
}
0 votesVote for this answer Unmark Correct answer

Recent Answers


Suneel Jhangiani answered on August 24, 2015 14:51

You actually need to get the selected value from the DropDownList and not the TreeHelper.

DropDownList sizes = (DropDownList)item.FindControl("sizeVariants");
var test = sizes.SelectedItem.Value;
0 votesVote for this answer Mark as a Correct answer

Chris Hinds answered on August 24, 2015 15:07

Thanks. I don't want to actually get it from the DropDownList. I was just using this as an example of how a control can extract the property I want to get:

DataTextField="Size"

I want to be able to call the TreeHelper method and then get the list of sizes from the returned list of TreeNodes

1 votesVote for this answer Mark as a Correct answer

Chris Hinds answered on August 24, 2015 15:48

Thanks ever so much. I have been banging my head against this all morning. Cheers.

0 votesVote for this answer Mark as a Correct answer

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