Default.aspx

View Code
<%@ 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 id="Head1" runat="server">
    <title>无标题页</title>
</head>
<body style="font-size: 12px">
    <form id="form1" runat="server">
    <div>
        <table style="border-right: #009999 thin ridge; border-top: #009999 thin ridge;
            border-left: #009999 thin ridge; width: 354px; border-bottom: #009999 thin ridge;
            height: 73px">
            <tr>
                <td colspan="3" style="text-align: center">
                    <strong><span style="font-size: 12pt; color: #000099">ASP.NET中应用视图</span></strong></td>
            </tr>
            <tr>
                <td colspan="3">
                    <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
                        Height="4px" Width="409px">
                        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#E3EAEB" />
                        <EditRowStyle BackColor="#7C6F57" />
                        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
                        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="White" />
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

Default.aspx.cs

View Code
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)
    {
        SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strCon"]);//创建数据库连接
        SqlDataAdapter dap = new SqlDataAdapter("select * from View_1", con);//查询视图中数据
        DataSet ds = new DataSet();//创建数据集
        dap.Fill(ds, "table");//填充数据集
        GridView1.DataSource = ds;//绑定数据源
        GridView1.DataBind();//绑定GridView控件
    }
}

 

posted on 2013-03-21 02:53  松竹梅  阅读(489)  评论(0编辑  收藏  举报