Friday, March 27, 2009

Create a ASP.NET Dynamic Data Web Site Using Scaffolding


The basic requirement for Dynamic data web site:

1) Microsoft Visual Studio 2008 Service Pack 1 or Visual Web Developer 2008 Express Edition Service Pack 1.
2) Microsoft SQL Server 2005 or Microsoft SQL Server 2008.

Introduction
Using this Dynamic Data web site we can create data driven web application easily, using the LINQ to SQL or Entity Frame work data model. In the below example show using LINQ TO SQL. During the run time the Dynamic Data discover LINQ TO SQL and determining how to render UI from the data model. The Detailview, Formview, Gridview, Listview controls are used in this Dynamic data application to display the data, edit the data, and to delete the data.

Creating Dynamic Data Web Site

1) Open a project in VS2008 select the Dynamic Data Web Application, Click OK.
2) After creating the Solution, Right Click on the Solution Explore select
AddèNewItem

3) In the Add New Item Dialog Box select the LINQ to SQL Class template.
4) From the Server Explorer drag and drop the table from the SQL server.
5) Open the Global.asax and un coment the following line.

‘model.RegisterContext(GetType(YourDataContextType), New ContextConfiguration() With {.ScaffoldAllTables = False})

6) Change the ‘YourDataContextType’ with your DataContextClass Name in the above line. The DataContextClass name is the name of the LINQ to SQL Class template name followed by DataContext. You can find it in designer class page of LINQ to SQL Class file. Ather that set ScaffoldAllTables = True.
7) Now Build and run the page you see the cool Dynamic Data web site

Enjoy !

Friday, March 6, 2009

Populating GridView in ASP.NET

Basic Code for populating the Gridview in ASP.NET
Using C#
SqlConnection con = new SqlConnection("your connection string comeshere");
SqlDataAdapter da = new SqlDataAdapter("select firstname,lastname from employees", con); DataSet ds= new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();

Using VB.NET
Dim con as SqlConnection =new SqlConnection ("your connection string comeshere")
dim da as SqlDataAdapter =new SqlDataAdapter ("select firstname,lastname from employees", con)
dim ds as new DataSet()
da.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()