.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

how to bind menu dynamically at runtime to database

Posted By:      Posted Date: September 18, 2010    Points: 0   Category :.NET Framework
Hi I'm new to ASP.Net. I need to bind data to menu navigation control from DataBase. These are the Tables I have...I know how to bind data from web.sitemap and xml, but not through database. If any changes are made in database, then automatically it should update in menu navigation control..plz guide me... Services --> E - Learning Education Software Products --> Education Individuals Corporate Customers --> Testimonials Careers --> Work Culture Current Openings About US --> Quality Policy Our Founder Our Team Thanks in Advance... even i can write code for it .but the main problem is that i dont know how i should create table structure .also navigate url column plz help

View Complete Post

More Related Resource Links

Dynamically bind to often changing database



Please point me to the right forum if this is not correct - I do appreciate it :-)

At work we have a database that needs a table maintenance utility written in c#/aspx/webforms. The database has about 45 tables and that could change fairly frequently.

The utility needs to present the user with a drop down of all the tables in the database, (ok - easy so far. I can get this dynamically from the database to allow for addition/deletion of tables). The user chooses a table name and is presented with the data in the table. The user can edit the data, delete or insert rows, page through the data, etc. I am guessing this is a gridview.

I can get the columns for the selected table name dynamically from the database too, but I do not seem to be able to write a generic page that uses code to bind the gridview to the data and lets the user page, insert or delete rows, etc.

In the designer a sql datasource on non-changing tables this would be easy. (Point the sds at the table, write a couple of stored procedures to add/delete/select rows, etc and the job is done).

What I don't seem to be able to do is write a generic page that will cope with dynamic binding of the grid to the database. i want to write a page that is fairly 'decoupled' from changes in the database but will still be able to provide a useful table-maintenance type tool.

.NET Reflection: Dynamically Bind Your Data Layer to Stored Procedures and SQL Commands Using .NET M


One major inconvenience of using SQL stored procedures from code is having to match type information. You have to write long wrapper functions around the procedures just to expose the data types. In the .NET Framework, however, the reflection services of the System.Reflection namespace allow you to query rich metadata that describe data types. This article explains how to use reflection in .NET to end your stored procedure nightmares. The author creates four custom classes, including one that generates a SQLCommand object based on the metadata of a method. Using this library, you'll be on your way to automating the generation of stored procedures.

Atif Aziz

MSDN Magazine August 2002

Dynamically Create a Database (LINQ to SQL)

 Hello... I want to create an install script for a simple little CMS I have created for myself... I want to pass the connection string and then create my tables. I found the following example on MSDN: http://msdn.microsoft.com/en-us/library/bb399420.aspx My question is how do I pass the username and password to the DB... or even better if there is an example of this somewhere that would be great.   Thanks!


the database result is as follows DATE     code   class1 class2  class3 1/8/10     M1     10       20     30     3/8/10     V2      20       30     10      1/8/10      H1      1           2      3         7/8/10     ! ! 8/8/10     !M2    5      5      5       3/8/10     B2      4      4     4       1/8/10     V1      3      7     3       THE OUTPUT SHOULD BE AS FOLLOWS:- DATE           M1                          M2           

Dynamically Generated Dynamic Menu Items Width Question


I have the following Menu:

<asp:Menu ID="MainMenu" runat="server" Orientation="Horizontal" 
	DynamicVerticalOffset="2" DynamicHorizontalOffset="2" 
	StaticEnableDefaultPopOutImage="false" DynamicEnableDefaultPopOutImage="false" >
        <StaticMenuItemStyle BackColor="#0099cc" ForeColor="#eeeeee" Font-Names="Arial" Font-Size="11" Height="18" HorizontalPadding="10" VerticalPadding="3"  />
	<StaticHoverStyle BackColor="#336699" ForeColor="#ffffff" Font-Names="Arial" Font-Size="11" />
	<DynamicMenuItemStyle BackColor="#0099cc" ForeColor="#eeeeee" Font-Names="Arial" Font-Size="10" Height="18" 
		HorizontalPadding="10" VerticalPadding="3" />
	<DynamicHoverStyle BackColor="#336699" ForeColor="#ffffff" Font-Names="Arial" Font-Size="10" />					
		<asp:MenuItemBinding DataMember="Item" TextField="Title" />
		<asp:MenuItemBinding DataMember="SubItem" TextField="Title" />						

Need some advice on database runtime manipulation



I've written a database app (Visual C# Express 2010 and Compact 3.5) using the standard drag-and-drop tools. This all works as expected but I want to extend the functionality to allow users to open any database with the same schema i.e. not restrict them only to the "hard coded" database.

This is where things get problematic for me. Can I use the existing project as a "template" and somehow associate any conforming database with it? Is there any better way of achieving this?

Any advice or (even better) sample code/tutorials/links will be greatly appreciated.

dynamically populating the database in the dropDownlist using c# in asp.net


hi everyone , plz listen my question very carefully

i have 2 tables  Desgn & EmpForm

Desgn table is lik this

CREATE TABLE [dbo].[Desgn](
    [DesignationCode] [int] IDENTITY(1,1) NOT NULL,
    [DesignationName] [varchar](50) NOT NULL,
    [DesignationCode] ASC

EmpForm table is like this

CREATE TABLE [dbo].[Empform](
    [EmpId] [varchar](50) NOT NULL,
    [EmpName] [varchar](50) NOT NULL,
    [EmpSalary] [numeric](18, 0) NULL,
    [EmpDesignationcode] [numeric](18, 0) NOT NULL,
    [EmpDateofBirth] [date] NOT NULL

now my ques is i want to dynamically populate the dropdown list of designation on the basis of the code but instead of code name should get populated .i have written the code like this 

public void Populate1()
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["co

Dynamically Generate No of Control(like Label) depend upon database no of item


I have a requirment like 

i required a dynamically generated Control (like Label) depend upon Database no of item


  If i fetch Database text (like Name) fieldd 3 time than i am intrested to generate  label 3 time

for (int i=0;i<table.row.count;i++)


label label[i]=table.row[i][0].Tostring();


How can do the above because label[i] is not allowed

Khurram Shahzad

Unable to create table dynamically in database


I am able to create database through script generated by SQL Server 2008 but unable to create tables from generated script. Please indicate if any step is missing.


************* Code *******************

 public bool CreateAppTables(string DatabaseName, string ConnectionString)
        string DatabaseScript;
        DatabaseScript = Activity.readTextFile(HttpContext.Current.Server.MapPath(".") + "/functionalscripts/CreateTablesonly.sql");
        DatabaseScript = DatabaseScript.Replace("DatabaseNametoChange", DatabaseName);
        return ActionQueryDB(DatabaseScript, ConnectionString);


 public bool ActionQueryDB(string SQLStatement, string ConnectionString)
        //  SqlConnection cn;

        OleDbConnection cn = new OleDbConnection();

        cn.ConnectionString = ConnectionString;
            OleDbCommand cmd = new OleDbCommand();
            cmd.CommandText = SQLStatement;
            cmd.Connection = cn;

            return true;
        catch (Exception ex)

            return false;


****************** Contents of text file appe

I am unable to create dynamic menu from database


Hi Expert,

I am unable to create dynamic menu from database. I have made two tables for this work.

First table is Menu which stores menu id and its relevant name.
MId Text
1 File
2 Edit
3 View

Second table is subMenu which stores submenus which will be linked to the menu table with menu id.

SId Text MID
1 New 1
2 Open 1
3 Save 1
4 Cut 2
5 Copy 2

the menu should be created dynamically from the database, each menu should be displayed in single row

when we click on a menu the submenus are displayed in rows that in expand & contrast form

how to design & develope this page

change sub menu position dynamically using jquery



I have created horizontal menu like below...

<!--<ul id="topnav">
    <li><a href="#">Link 1</a></li>
    <li><a href="#">Link 2</a></li>
        <a href="#">Link 4</a>
            <a href="#">Subnav Link</a> |
            <a href="#">Subnav Link</a> |
            <a href="#">Subnav Link</a>
    <li><a href="#">Link 3</a></li>

problem is in my css i assigned margin-left:0px  for span.so all my sub navs align to left.but i want to align sub nav under the mail nav.means i need to change align-left property of css dynamically using jquery.

means first sub nav link should be below 'link4' not under 'link1'

so i added fol

Bind Event Receiver to List Dynamically


Hey all, I've been working on a little application page that will give users the option to say whether a list should allow duplicate title entries.

I am able to pass the current list GUID to the application page using this:

<UrlAction Url="~site/_layouts/preventduplicates.aspx?List={ListId}"/>

within a custom action which I've added to the list settings. I'm kind of stuck now....


I'm not sure how to grab this GUID out of the url, and use it so I can bind the current list with my event receiver. Every example I've seen of binding has used a hard coded list name which is fine as an example, but isn't the best for real applications. Or is there a way to use the GUID to get the lists name which I can then pass to the spweb.Lists[var] ? Since I won't know the list name beforehand.

Hope all of that makes sense, any suggestions are appreciated.

Bind combox, ListBox to SQL database column


Hi everyone

  I am having problem where I want to bind a column of the database to the Combobox so that Item of the combobox are present in the database

for example I have a table named Animals which is in the following format

ID   Animal

1    Dog

2    Cat

3    Horse

4   Goat


So the Item of the Combobox are Dog, Cat, Horse and Goat.  I had tried to bind the database to ObservableCollection First and then bind that ObservableCollection to the combobox.

   public class NameList : List<PersonName>
	private LikesLINQDataContext newlikes = new LikesLINQDataContext();

	List<string> depart = new List<string>();

	 public NameList(): base()
		foreach (var lol in newlikes.Likes)

		foreach (stri

Dynamically upload and use usercontrol at runtime


Hi All,

I was wondering if it is possible to upload the  .ascx and .ascx.vb of a custom usercontrol into my project directory at runtime via an upload control and then after that use through a database query point my page to load that newly uploaded control via (LoadControl(<newlyUploadedControl>)?

Please kindly advice and assist.

Thank you in advance.

Warmest Regards,


Dynamically display images from SQL database


I've found several good examples of how to display an image from a database, but I'm looking for an example of how to display an image within an aspx page with other controls.  This code works fine, but only displays the image by itself on the page (item4 is the image data, stored in SQL Server as type=Image):

Stream strmImage = new MemoryStream(item4.Image_Data.ToArray());
byte[] buffer = new byte[4096];
int byteSeq = strmImage.Read(buffer, 0, 4096);
while (byteSeq > 0)
    Response.OutputStream.Write(buffer, 0, byteSeq);
    byteSeq = strmImage.Read(buffer, 0, 4096);

I've also tried to save the data as a System.Drawing.Image, but like using the Response.Outputstream instruction above, it immediately outputs the image and nothing else on the page.

System.Drawing.Image myImage = System.Drawing.Image.FromStream(strmImage);
myImage.Save(Context.Response.OutputStream, ImageFormat.Jpeg);

In simple terms, I want to get the image from the database, stick it in a variable or something like that, then display it in a table.  Any suggestions?



How to bind text containing HTML and ASP.NET tags from database



I have to show dynamic charts to clients.

I created table: ChartCodes

ChartCodeID     Code

1                      <asp:SqlDataSource ID='SqlDataSource_Chart1' runat='server' ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand='Usp_GetTotalEmissions_Org_chart' SelectCommandType='StoredProcedure'><SelectParameters>< . . .. . . . .

I wrote code of chart with sqldatasource in database column.

My problem is I could not able bind. I used DataList Control with a template and literal.

Bind literal with <%# Eval("Code") %>

But In sql I have ASP.NET tags <%  %>.   and when processing process %>, it assumes asp.net ends and wrote other text as it is in out put.

Please help me to find how to bind this text. Or any other Idea to display graphs from database as per user selection.

How to load "Database Instance" for "Database Trace Listener" at runtime



I have been searching for a while now without success. On how when using EntLib 5.0 Logging, Data; to be able to set the database (i.e. the connection string) at runtime for a Database Trace Listener. The reason being we will have the same configurations on all levels of the environments (dev, test, stage, prod), but the connection string is different for each and we do not store the connection string data in the config file. The connection string data is loaded using a custom configuration manager for security reasons.


Any help and any code sample much appreciated. 



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend