Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • vijay 129 posts 152 karma points
    Jan 21, 2010 @ 08:42
    vijay
    0

    How to create a datatype which displays Node names in dropdown?

    Hi all,

    Below i m creating a dropdown datatype which reads the Nodes  and populates the dropdown.

    Please check my code and tell me where i m doing wrong because i'm getting Null reference exception error

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    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 umbraco.presentation.nodeFactory;


    public partial class EditAdminUser : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor
    {
        protected string umbracoValue;
        protected void Page_Load(object sender, EventArgs e)
        {
            Fill_DD_Category();
        }   
        public object value
        {
            get
            {
                return umbracoValue;
            }
            set
            {
                umbracoValue = value.ToString();
            }
        }
        public void Fill_DD_Category()
        {
            DataTable dt1 = new DataTable();
            dt1.Columns.Add(new DataColumn("nodeName", typeof(string)));
            dt1.Columns.Add(new DataColumn("nodeID", typeof(string)));
            DataRow dr;
            dr = dt1.NewRow();
            dr["nodeName"] = "Please select category";
            dr["nodeID"] = "0";
            dt1.Rows.Add(dr);

            Node CurrentNode = Node.GetCurrent();
            Nodes nodes = CurrentNode.Children;

            foreach (Node node in nodes)
            {
                dr = dt1.NewRow();
                dr["nodeName"] = node.Name;
                dr["nodeID"] = node.Id;
                dt1.Rows.Add(dr);
            }
            DD_Category.DataSource = dt1;
            DD_Category.DataTextField = "nodeName";
            DD_Category.DataValueField = "nodeID";
            DD_Category.DataBind();
        }
    }

    ---vijay.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 21, 2010 @ 10:27
    Dirk De Grave
    1

    Show the complete error message, including the line and you'll probably get a clue of what object is null!

     

    Cheers,

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft