|
Hi..
I have seen ur post,my requirement is similar to urs in c#..
But a bit more complex i need nth level of submenu...
Main menu
Sub menu 1
sub menu 2
sub menu 3
and so on
Kindly help me out..
-- modified 11-Jan-12 6:54am.
|
|
|
|
|
Hi Ravi Selvaraj,
It is a nice and simple article to follow.
What if I need to bind Sub-Sub menus.
How can I achieve this.
Thanks for the post again
|
|
|
|
|
when we click on the menuitem so we can easily find that which item has been clicked.
but if we have to find that wat is the catID of that particular category so what have to do.
Please give me the solution.
Thanks
|
|
|
|
|
Hi Everyone!
just want to find out if someone has tried the BindMenu. I did and it seem not to work with Internet Explorer 8. Can someone verifer for me?
Thanks and best regards!
|
|
|
|
|
hi,
it is properly working on all the browser.
|
|
|
|
|
|
nice idea. 2 questions:
1. When you have sub-sub-sub link, how will it look?
The link will be placed into SubSubSubCategory table? To make logic, you have to generate new tables in DB, haven't you?
Example:
Home
>2008
>Books
>Articles
>SomeLink
Not very good.
2. How do you change links? Directly in DB?
Point of view:
Better to make all in one table, example - <b>dbo.SiteMap</b>, with default columns for xml sitemap PLUS
[Id] - id of link element, is a KEY
[Id_2] contain id of id for sub element
[Id_3] contaain id of id of id for sub sub element. Then Id_2 MUST be 0.
... and so on
Example, when Id_x == 0, then it doesn't belong to sub directory
Id Id_2 Id_3 Id_4 [Title] [Url] [Description] [Comments] [idRole]
1 0 0 0 Home ~/ Bla-bla root 1
2 1 0 0 2008 ~/2008 bla-bla '08 year 1
4 0 2 0 Books ~/2008/Books "" "" 1
3 0 2 0 Articles ~/2008/Articles "" "" 1
4 0 0 3 SomeLink ~/2008/Articles/Lnk "" "" 1
Where idRole is RELATION to <b>dbo.aspnet_Roles</b> or any other role table of your DB
where idRole == 1 is Public.
Som you will gain some features and bugs if you follow this way:
+ as you see, it looks like matrix, and so you can include each row into several submenus. Sitemap never provide this feature
+ you can extent and make it deeper how it is needed
+ simple to change
- easy to break without nicely created interface for managing tables.
- you have to provide logic for cascade delete and cascade modify.
__
Yurii
|
|
|
|
|
I am new to ASP.NET and VB code. Is there a way to make the menus horizontal instead of vertical?
|
|
|
|
|
Yes, you can make menus to be displayed horizontal and vertical.
There is a property for menus called as Orientation set them to horizontal or vertical.
|
|
|
|
|
Do you by any chance have the C# code for this? I have been trying to changes the lines to C# and I am stuck on this line:
Dim mNode As New MenuItem(CType(categoryRow("CatName"), String), "", "", "~/DetailView.aspx?CatID=" + CType(categoryRow("CatId"), String), "_parent")
These are few of the things I tried doing:
MenuItem mNode = new MenuItem(Convert.ToString(categoryRow["CatName"], String), "", "", "~/DetailView.aspx?CatID=" + Convert.ToString(categoryRow["CatId"], String), "_parent");
MenuItem mNode = new MenuItem(categoryRow["CatName"].ToString, "", "", "~/DetailView.aspx?CatID=" + categoryRow["CatId"].ToString, "_parent");
This is the error I get in both cases:
Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'int'
Thank you.
|
|
|
|
|
Here is the code in C#.
MenuItem mNode = new MenuItem (Convert.ToString(categoryRow["CatName"]),"","",<br />"~/DetailView.aspx?CatID="+Convert.ToString(categoryRow["CatId"]),"_parent");
it seems you have passed an extra parameter(i.e string) to Convert.ToString() method.
Happy Programming.
|
|
|
|
|
Hi Ravi,
Thank you so much for your reply.
However, I am still getting the error:
CS0029: Cannot implicitly convert type 'string' to 'int'
I did replace the line with the code that you had sent me and it still doesn't work.
private void BindMenu()
{
String connectionString = crafters.DbConnectionString;
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter dadCategories = new SqlDataAdapter("SELECT CatId,CatName FROM Category order by CatName", con);
SqlDataAdapter dadSubCat = new SqlDataAdapter("SELECT SubCatId,CatId,SubCatName FROM SubCategory order by SubCatName", con);
DataSet dsCat = new DataSet();
using (con)
{
con.Open();
dadCategories.Fill(dsCat, "Category");
dadSubCat.Fill(dsCat, "SubCategory");
}
DataColumn parentColumn =
dsCat.Tables["Category"].Columns["CatID"];
DataColumn childColumn =
dsCat.Tables["SubCategory"].Columns["CatId"];
DataRelation relation =
new System.Data.DataRelation("Children",
parentColumn, childColumn);
dsCat.Relations.Add(relation);
int count = 0;
foreach(DataRow[] categoryRow in dsCat.Tables["Category"].Rows)
{
MenuItem mNode = new MenuItem(Convert.ToString(categoryRow["CatName"]), "", "", "~/DetailView.aspx?CatID=" + Convert.ToString(categoryRow["CatId"]), "_parent");
Menu1.Items.Add(mNode);
}
I really need your help on this. Thank you in advance.
|
|
|
|
|
 Try this complete code.
I have tested this code it is working fine.
internal void BindMenu()
{
string cs = WebConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ConnectionString;
SqlConnection con = new SqlConnection(cs);
SqlDataAdapter dadCategories = new SqlDataAdapter("SELECT CatId,CatName FROM Category order by CatName", con);
SqlDataAdapter dadSubCat = new SqlDataAdapter("SELECT SubCatId,CatId,SubCatName FROM SubCategory order by SubCatName", con);
DataSet dsCat = new DataSet();
using (con)
{
con.Open();
dadCategories.Fill(dsCat, "Category");
dadSubCat.Fill(dsCat, "SubCategory");
}
dsCat.Relations.Add("Children", dsCat.Tables["Category"].Columns["CatId"], dsCat.Tables["SubCategory"].Columns["CatId"]);
int count = 0;
foreach (DataRow categoryRow in dsCat.Tables["Category"].Rows)
{
MenuItem mNode = new MenuItem(Convert.ToString(categoryRow["CatName"]), "", "", "~/DetailView.aspx?CatID=" + Convert.ToString(categoryRow["CatId"]), "_parent");
Menu1.Items.Add(mNode);
DataRow[] subCatRows = categoryRow.GetChildRows("Children");
foreach (DataRow row in subCatRows)
{
string subCatName = Convert.ToString(row["SubCatName"]);
MenuItem subCatItems = new MenuItem(subCatName, "", "", "~/DetailView.aspx?CatID=" + Convert.ToString(row["CatId"]) + "&SubCatID=" + Convert.ToString(row["SubCatId"]), "_parent");
Menu1.Items[count].ChildItems.Add(subCatItems);
}
count = count + 1;
}
}
Happy Programming 
|
|
|
|
|
Hi this is suma,
i used this code but am getting error like
This constraint cannot be enabled as not all values have corresponding parent values.
SqlDataAdapter dadCategories = new SqlDataAdapter("SELECT CatId,CatName FROM Category order by CatName", con);
in this code i have to use the where condition ex: product id=1
but i am getting the error. can u please suggest me.
|
|
|
|
|
String connectionString = "Initial Catalog=mydata; Data Source=GOD-E4462345A8F; User Id=sa;Password=deepika";
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter dadCategories = new SqlDataAdapter("SELECT * FROM menu", con);
SqlDataAdapter dadSubCat = new SqlDataAdapter("SELECT * FROM menudata", con);
// Add the DataTables to the DataSet
DataSet dsCat = new DataSet();
using (con)
{
con.Open();
dadCategories.Fill(dsCat,"MENU");
dadSubCat.Fill(dsCat,"menudata");
int count = 0;
foreach (DataRow categoryRow in dsCat.Tables["menu"].Rows)
{
MenuItem mNode = new MenuItem(Convert.ToString(categoryRow[0] ));
Menu1.Items.Add(mNode);
}
foreach (DataRow categoryRows in dsCat.Tables["menudata"].Rows )
{
int i,p;
i= dsCat.Tables[1].Columns .Count;
p=1;
while (p <i)
{
MenuItem mNodes = new MenuItem(Convert.ToString(categoryRows[p]));
Menu1.Items[count].ChildItems.Add(mNodes);
p++;
}
count++;
}
}
|
|
|
|
|