This is a migrated thread and some comments may be shown as answers.

Create RadMenu programatically

1 Answer 198 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Dani
Top achievements
Rank 1
Dani asked on 01 Feb 2012, 12:31 AM
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

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Feb 2012, 06:56 AM
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.
Tags
Menu
Asked by
Dani
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or