Create RadMenu programatically

2 posts, 0 answers
  1. Dani
    Dani avatar
    3 posts
    Member since:
    Jan 2007

    Posted 31 Jan 2012 Link to this post

    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

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 01 Feb 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top