Default. aspx
Copy codeThe Code is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<! 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> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: GridView ID = "GridView1" runat = "server" CellPadding = "4" ForeColor = "#333333"
GridLines = "None">
<RowStyle BackColor = "# EFF3FB"/>
<FooterStyle BackColor = "#507CD1" Font-Bold = "True" ForeColor = "White"/>
<PagerStyle BackColor = "# 2461BF" ForeColor = "White" HorizontalAlign = "Center"/>
<SelectedRowStyle BackColor = "# D1DDF1" Font-Bold = "True" ForeColor = "#333333"/>
<HeaderStyle BackColor = "#507CD1" Font-Bold = "True" ForeColor = "White"/>
<EditRowStyle BackColor = "# 2461BF"/>
<AlternatingRowStyle BackColor = "White"/>
</Asp: GridView>
</Div>
</Form>
</Body>
</Html>
Default. aspx. cs
Copy codeThe Code is as follows:
Using System;
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;
Public partial class _ Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
DataSet dsSource = new DataSet (); // create a source DataSet
DataSet dsTarget = new DataSet (); // create the target DataSet
String conStr = ConfigurationManager. ConnectionStrings ["conStr"]. ToString ();
Using (SqlConnection con = new SqlConnection (conStr) // create a data connection
{
// Create a data adapter
SqlDataAdapter sda = new SqlDataAdapter ("select * from DictionaryType", con );
Sda. Fill (dsSource, "DictionaryType"); // Add the dictionary class to the source Dataset
Sda = new SqlDataAdapter ("select * from DictionaryItem", con );
Sda. Fill (dsTarget, "DictionaryItem"); // Add the dictionary value to the target dataset.
}
DsTarget. Merge (dsSource); // combines the DictionaryType table of the source dataset into the target dataset.
GridView1.DataSource = dsTarget. Tables ["DictionaryType"];
GridView1.DataBind ();
}
}