Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

Dynamic Website Project allows you to create customizable support pages. This can be really helpful if part of your job is to create boring support pages. Recently, I had to create few support pages so I thought why not try the Dynamic Website Project. So, I added the LINQ to SQL as the data source and used one of the databases to create the support pages.

In our application whenever a row in the database is updated we update the DateModified field. This can easily be performed inside the GridView_RowUpdating event as shown below (ListDetailsTempate.aspx):

 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        e.NewValues["DateModified"] = DateTime.Now;

Now, whenever you update any row the DateModified field wil be modified automatically.

Another thing that I needed to add was the support for choosing multiple databases. If I add a table from a different database to the LINQ to SQL designer then it will use the new database as the primary database and you will not be able to access the old database tables. This is because the connetionString will be overriden and will be pointing to the new database. To fix this issue I created a DropDownList which is populated with all the names of the databases and their respective context classes(The context classes will be the classes automatically generated by the LINQ to SQL).

  <dataContext name = "Exams" type="CasaSupportPages.DatabaseContexts.ExamsDataContext" />
  <dataContext name="Users" type="CasaSupportPages.DatabaseContexts.UsersDataContext" />

Here is the code to populate the DropDownList:

 private void PopulateDropDownList()
            XDocument doc = XDocument.Load(Server.MapPath("~/ContextSettings.xml"));

            foreach (var element in doc.Root.Elements("dataContext"))
                ddlDatabases.Items.Add(new ListItem((string)element.Attribute("name"),(string) element.Attribute("type")));   

Finally, after selecting the correct database you press the button and now your Dynamic Website will be created using the new database.

public static void SetDatabaseContext(string contextType)
            Configuration config = WebConfigurationManager.OpenWebConfiguration("~/");
            ConfigurationSectionGroup group = config.GetSectionGroup("system.web.extensions");
            ConfigurationSection section = group.Sections["dynamicData"];
            PropertyInformation propInformation = section.ElementInformation.Properties["dataContextType"];
            propInformation.Value = contextType;

This way you can create support pages (dynamic pages) using multiple databases.

Posted on Thursday, January 24, 2008 12:25 PM | Back to top

Comments on this post: Using Multiple Databases with the Dynamic Website Project

# web site development
Requesting Gravatar...
hi dary online supportry i need dynamic html code about web site development & together with mysql_db using php code connected.please healp me because iam student& also sick ,but i have aproject.
Left by zinabu alemayehu on May 08, 2008 3:13 AM

# web site development
Requesting Gravatar...
I work in a firm as a web developer. But i want to work web developing at home and want to earns some money. But how can i get work. Plz give me a suggestion.
Left by munna on Jun 23, 2008 11:15 PM

Your comment:
 (will show your gravatar)

Copyright © Mohammad Azam | Powered by: