databinding menu to Stored Procedure

2 posts, 0 answers
  1. Mmm
    Mmm avatar
    9 posts
    Member since:
    Mar 2011

    Posted 19 Sep 2011 Link to this post

    I have following code in my Master Page C# Code. Its just throwing me error on "RadMenu1.DataSource = MenuCreation.ExecuteNonQuery();"
    that Object Reference not found. This code does work elsewhere but just not working in Master Site. Can someone help. How can I use RadMenu in my master site

    my stored procedure name is AllMenu which basically select all data from table name MyMenus
    Also my stored procedure sql is simple. it is "SELECT id, text, (CASE WHEN parentid = 0 THEN  NULL ELSE parentid END) FROM MyMenus"

                SqlCommand MenuCreation= new SqlCommand();
                SqlConnection dbconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLDB"].ConnectionString);
                MenuCreation.Connection = dbconnection ;
                MenuCreation.CommandType = CommandType.StoredProcedure;
                MenuCreation.CommandText = "AllMenu";

                ConnectionState previousConnectionState = dbconnection.State;

                RadMenu1.DataSource = MenuCreation.ExecuteNonQuery();

                RadMenu1.DataFieldID = "ID";
                RadMenu1.DataFieldParentID = "ParentID";

                RadMenu1.DataTextField = "Text";
                RadMenu1.DataValueField = "ID";
                RadMenu1.DataNavigateUrlField = "URL";

  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 22 Sep 2011 Link to this post

    Hello Mmm,

    The reason your code doesn't work is because you are calling ExecuteNonQuery, which returns an int stating the number of rows affected by the query.

    In order to return the result of the Stored Procedure, you need to use the SqlDataAdapter class and fill a DataTable that you will pass as the DataSource for the RadMenu.

    I hope that helps.
Back to Top