1 Replies - 2111 Views - Last Post: 25 September 2012 - 07:01 AM Rate Topic: -----

#1 arsalankhanzada  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 10-September 12

Category &sub Category

Posted 25 September 2012 - 06:32 AM


Creating a dynamic Menu from database with category and subcategory

Hi ,

I want to create a dynamic menu from database which shows category and subcategory.

For example please reffer the following site. (right side menu / vertical menu)

http://www.oreilly.d...pics/perl.html#

Please revert back to me as soon as possible.

Regards,
Arsalan


View Postarsalankhanzada, on 25 September 2012 - 06:28 AM, said:


Creating a dynamic Menu from database with category and subcategory

Hi ,

I want to create a dynamic menu from database which shows category and subcategory.

For example please reffer the following site. (right side menu / vertical menu)

http://www.oreilly.d...pics/perl.html#

Please revert back to me as soon as possible.

Regards,
Arsalan

THIS IS THE CODE..

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Menu.aspx.cs" Inherits="Menu" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Untitled Page</title>

        <script language="javascript">

            function showsubmenu(id)

            {

                var subcat=document.getElementById(id);

                if(subcat.style.display == 'none')

                {

                    subcat.style.display= 'block';

                }

                else

                {

                    subcat.style.display= 'none';

                }

               

            }

        </script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:DataList ID="DataList1" runat="server"

            onitemdatabound="DataList1_ItemDataBound">

            <ItemTemplate>

                <asp:Label ID="id" runat="server" Text='<%# Eval("cat_id") %>' Visible="false"></asp:Label>

                <asp:HyperLink ID="MainCat" Text='<%# Eval("cat_name") %>' runat="server" NavigateUrl="#"></asp:HyperLink>

                <asp:Panel ID="panelsubcat" runat="server" Style="display: none;">

                    <asp:DataList ID="subcat" runat="server">

                        <ItemTemplate>                           

                                --><asp:LinkButton ID="subcat" Text='<%# Eval("cat_name") %>' runat="server" PostBackUrl='<%# Eval("cat_id","~/Catagory.aspx?Cat={0}") %>'></asp:LinkButton>

                        </ItemTemplate>

                    </asp:DataList>

                </asp:Panel>

            </ItemTemplate>

        </asp:DataList>

    </div>

    </form>

</body>

</html>

 

 

ASPX.CS CODE:

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Data.SqlClient;

using System.Data;

 

public partial class Menu : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        SqlCommand cmd = new SqlCommand();

        SqlDataReader dr;

        SqlConnection con = new SqlConnection("user id=sa ; password = abc ; data source= .\\SQLEXPRESS; database= MenuListing");

        con.Open();

        cmd.CommandText = "select * from category where sub_cat_id is Null";

        cmd.Connection = con;

        dr = cmd.ExecuteReader();

        DataList1.DataSource = dr;

        DataList1.DataBind();

        con.Close();

    }

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)

    {

        Panel p = (Panel)e.Item.FindControl("panelsubcat"); //Find panel

        HyperLink l = (HyperLink)e.Item.FindControl("MainCat"); //Get Main category

        l.Attributes.Add("onclick", "showsubmenu('" + p.ClientID + "')");

        SqlCommand cmd = new SqlCommand();

        SqlDataReader dr;

        SqlConnection con = new SqlConnection("user id=sa ; password = abc ; data source= .\\SQLEXPRESS; database= MenuListing");

        con.Open();

        Label id=(Label)e.Item.FindControl("ID"); //Find main category id

        int catid = Convert.ToInt16(id.Text.ToString());

        cmd.CommandText = "select * from category where sub_cat_id="+catid;

        cmd.Connection = con;

        dr = cmd.ExecuteReader();

        DataList d = (DataList)e.Item.FindControl("subcat"); //Find another gridview

        d.DataSource = dr;//Set datasorue

        d.DataBind();       

    }



This post has been edited by modi123_1: 25 September 2012 - 09:09 AM
Reason for edit:: removed sizes


Is This A Good Question/Topic? 0
  • +

Replies To: Category &sub Category

#2 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 447
  • View blog
  • Posts: 3,095
  • Joined: 12-January 10

Re: Category &sub Category

Posted 25 September 2012 - 07:01 AM

I dont see a question and what is up with the large font?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1