Default.aspx
Copy Code code 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 ">
<title> Untitled Page </title>
<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"/>
<editrowstyle backcolor= "#2461BF"/>
<alternatingrowstyle backcolor= "White"/>
</asp:GridView>
</div>
</form>
</body>
Default.aspx.cs
Copy Code code 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 (); To create a source data set
DataSet Dstarget = new DataSet (); To create a destination dataset
String constr = configurationmanager.connectionstrings["Constr"]. ToString ();
using (SqlConnection con = new SqlConnection (CONSTR))//Create data connection
{
To create a data adapter
SqlDataAdapter SDA = new SqlDataAdapter ("select * from Dictionarytype", con);
Sda. Fill (Dssource, "Dictionarytype");//Add dictionary class to source dataset
SDA = new SqlDataAdapter ("select * from Dictionaryitem", con);
Sda. Fill (Dstarget, "Dictionaryitem");//Add dictionary values to the destination dataset
}
Dstarget.merge (Dssource); Merge the Dictionarytype table of the source dataset into the target dataset
Gridview1.datasource = dstarget.tables["Dictionarytype"];
Gridview1.databind ();
}
}