Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Menu > Create RadMenu programatically

Not answered Create RadMenu programatically

Feed from this thread
  • Dani avatar

    Posted on Jan 31, 2012 (permalink)

    Hi all,

    I have one SQL table where I have all the data to load in RadMenu. All Items, links and design definitions.
    I can create all items programmatically into RadMenu but after I want to change the background image for each item based on the definition that I have in database. I know that we have this definition in skin css but I want to ignore the skin and I want to load the style programatically. For example:
    For item 1 I want a background with image 1
    For item 2 I want a background with image 2

    As well

    For Item 1 I want a rollover image with image 3
    For Item 2 I want a rollover image with image 4

    And 

    For Item 1 I want left image with image 5
    For Item 2 I want left image with image 6

    How I can do this programmatically?

    Regards,
    Daniel

    Reply

  • Posted on Feb 1, 2012 (permalink)

    Hello,

    Try the following code snippet.
    C#:
    protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               String str = System.Configuration.ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
               SqlConnection con = new SqlConnection(str);
               SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM [tablename]", con);
               DataTable dt= new DataTable();
               adapter.Fill(dt);
               RadMenu1.DataSource = dt;
               RadMenu1.DataFieldID = "id";
               RadMenu1.DataFieldParentID = "field1";
               RadMenu1.DataTextField = "field2";
               RadMenu1.DataSource = dt;
               RadMenu1.DataBind();
               RadMenu1.Items[0].CssClass = "item0css";
               RadMenu1.Items[1].CssClass = "item1css";
               RadMenu1.Items[0].ImageUrl = "~/Images/image5.gif";
               RadMenu1.Items[1].ImageUrl = "~/Images/image6.gif";
           }
       }
    CSS:
    <style type="text/css">
     .item0css
       {
          background:url("../Images/image1.jpg") !important;
       }
     .item1css
      {
        background:url("../Images/image2.jpg") !important;
      }
     .item0css :hover
      {
       background:url("../Images/image3.gif") !important;
      }
    .item1css :hover
      {
        background:url("../Images/image4.jpg") !important;
      }
    </style>

    Thanks,
    Princy.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Menu > Create RadMenu programatically
Related resources for "Create RadMenu programatically"

[  ASP.NET Menu Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]