Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

css Menu not working in Masterpage ...

$
0
0

Hi Friends,

I have created a css menu in masterpage in my web application. below is the code of masterpage :-

SqlConnection con = new SqlConnection();
con.ConnectionString = clsProperty.GetConnectionString;
con.Open();
SqlDataAdapter daMenu = new SqlDataAdapter("SELECT DISTINCT UserPermissionDetails.PageGroupId, PageGroupDetails.PageGroupName FROM UserPermissionDetails INNER JOIN " +
"UserGroupDetails ON UserPermissionDetails.UserGroupId = UserGroupDetails.UserGroupId INNER JOIN EmployeeDetails ON UserGroupDetails.UserGroupId = EmployeeDetails.UserGroup INNER JOIN " +
"PageGroupDetails ON UserPermissionDetails.PageGroupId = PageGroupDetails.PageGroupDetailsId WHERE (EmployeeDetails.EmpId =" + Session["EmpId"].ToString() + ") AND (UserPermissionDetails.ViewPage = 1)", con);
DataTable dtMenu = new DataTable();
daMenu.Fill(dtMenu);
if (dtMenu.Rows.Count > 0)
{

 // Here i am getting the parent menu ...names....
       int indexno = 0; 
       System.Web.UI.HtmlControls.HtmlGenericControl UL; //Here i am creating html ul tag .
       UL = new HtmlGenericControl("ul");
       UL.ID = "coolMenu"; // this is my css class ID 
       System.Web.UI.HtmlControls.HtmlGenericControl liParent;
       foreach (DataRow row in dtMenu.Rows)
       {
            liParent = new HtmlGenericControl("li");
            liParent.InnerText = row[1].ToString();

            System.Web.UI.HtmlControls.HtmlGenericControl ulChild = new HtmlGenericControl("ul"); // here i have ul tag
            SqlConnection conSubMenu = new SqlConnection();
            conSubMenu.ConnectionString = clsProperty.GetConnectionString;
            conSubMenu.Open();
            SqlDataAdapter daSubMenu = new SqlDataAdapter("SELECT PageDetails.Name, PageDetails.PageName, PageDetails.PagePath                FROM PageDetails INNER JOIN UserPermissionDetails ON PageDetails.PageGroup = UserPermissionDetails.PageGroupId AND PageDetails.PageId = UserPermissionDetails.PageId INNER JOIN UserGroupDetails ON UserPermissionDetails.UserGroupId = UserGroupDetails.UserGroupId INNER JOIN EmployeeDetails ON UserGroupDetails.UserGroupId = EmployeeDetails.UserGroup WHERE (UserPermissionDetails.PageGroupId =" + row[0].ToString() + ") AND (UserPermissionDetails.ViewPage = 1) AND (EmployeeDetails.EmpId =" + Session["EmpId"].ToString() + ")", conSubMenu);
             DataTable dtSubMenu = new DataTable();
            daSubMenu.Fill(dtSubMenu);
            if (dtSubMenu.Rows.Count > 0)
            {
                  int j = 0;
                  HyperLink link;
                  MenuItem objChildMenuItems;
                  System.Web.UI.HtmlControls.HtmlGenericControl li;  //. Here i have created li tag

                  foreach (DataRow rowSubMenu in dtSubMenu.Rows)
                 {
                            objChildMenuItems = new MenuItem();
                            li = new HtmlGenericControl("li");

                            link = new HyperLink();
                            link.ID = rowSubMenu[1].ToString();
                            link.Text = rowSubMenu[0].ToString();
                            link.NavigateUrl = rowSubMenu[2].ToString();
                            objChildMenuItems.Value = rowSubMenu[1].ToString();
                            objChildMenuItems.Text = rowSubMenu[0].ToString();
                            objChildMenuItems.NavigateUrl = rowSubMenu[2].ToString();
                            li.Controls.Add(link);
                            ulChild.Controls.Add(li);  // adding the li controls to ulchild tag ..

                  }

                 dtSubMenu.Dispose();
                 daSubMenu.Dispose();
                 conSubMenu.Close();

                 liParent.Controls.Add(ulChild); // Adding the ulchild cntrl to liparent tag
                 UL.Controls.Add(liParent); // Adding the liparent controls to Ul tag
                 Menustrip.Controls.Add(UL); // Adding the Ul tag to Menustrip div tag....
             }
     }
    dtMenu.Dispose();
   daMenu.Dispose();
   con.Close();

Below is the css :-

#coolMenu,
#coolMenu ul {
list-style: none;

}
#coolMenu
{
float: left;
width: 100%;
}
#coolMenu > li
{
float: left;
width: 16%;
/*background-image: url(Images/SpryMenuBarDown.gif);
background-repeat: no-repeat;
background-position: 60%;*/
}
#coolMenu li a
{
display: block;
height: 10px;
line-height: 2px;
padding: 6px;
text-decoration: none;
}
#coolMenu ul
{
position: absolute;
display: none;
z-index: 999;
}
#coolMenu ul li a
{
width: Auto;
text-align: left;
}
#coolMenu li:hover ul
{
display: block;
}
#coolMenu
{
font-family: Calibri;
font-size: 18px;
background: #EEE;
}
#coolMenu > li > a
{
/*color: #fff;*/
color: #333;
font-weight: bold;
}
#coolMenu > li:hover > a
{
background: #f09d28;
color: #000;
}
/* Submenu
------------------------------------------*/
#coolMenu ul
{
background: #EEE;
}
#coolMenu ul li a
{
color: #333;
}
#coolMenu ul li:hover a
{
background: #33C;
color: #FFF;
}

The above code works fine in the seperate default page ie wwebform.aspx but not in masterpage.master.

please give the solution.


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>