关闭

在一个已有的网站上加上Microsoft.Web.Atlas

标签: assemblystringaspservercompilationauthentication
1225人阅读 评论(0) 收藏 举报
分类:

1.

建一个 Bin 目录  将 Microsoft.Web.Atlas.dll 复制进去

2.

打开Web.Config 在

在“ <system.web>”内加入


  <pages>
   <controls>
    <add namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
    <add namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
   </controls>
  </pages>

3.在aspx文件中加入Atlas 例如

ajax.aspx

<%@ 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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
   <input type="text" id="asdf" />
        <atlas:ScriptManager ID="s1" runat="server" EnablePartialRendering="true" />
       
        <atlas:UpdatePanel ID="u1" runat="server">
            <ContentTemplate>
           
           
                <asp:GridView ID="GridView1" DataSourceID="ObjectDataSource1" DataKeyNames="ID" AutoGenerateColumns="false"
                    AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" runat="Server">
                    <Columns>
                        <asp:BoundField DataField="Name" />
                        <asp:BoundField DataField="Des" />
                    </Columns>
                </asp:GridView>
              
                           
                <asp:ObjectDataSource ID="ObjectDataSource1" TypeName="ProductInfo" SelectMethod="GetProducts"
                    UpdateMethod="UpdateProduct" DeleteMethod="DeleteProduct" runat="Server">
                    <UpdateParameters>
                        <asp:Parameter Name="ID" Type="Int32" />
                        <asp:Parameter Name="Name" />
                        <asp:Parameter Name="Des" />
                    </UpdateParameters>
                </asp:ObjectDataSource>
              
               
            </ContentTemplate>
        </atlas:UpdatePanel>
    </form>
</body>
</html>


ProductInfo.cs

using System;
using System.Data;
using System.Data.SqlClient;

public class ProductInfo
{
    const string conString =
      @"Data Source=./SQLEXPRESS;AttachDbFilename=c:/t/DataSourceDemo/App_Data/ASPNETDB.mdf;Integrated Security=True;User Instance=True";

    public static SqlDataReader GetProducts()
    {
        SqlConnection con = new SqlConnection(conString);
        string selectString = "SELECT * FROM Products";
        SqlCommand cmd = new SqlCommand(selectString, con);
        con.Open();

        SqlDataReader dtr =
          cmd.ExecuteReader(CommandBehavior.CloseConnection);
        return dtr;
    }
   
    public static void UpdateProduct(int Id,string Name, string des)
    {
        SqlConnection con = new SqlConnection(conString);
        string updateString = "UPDATE Products SET " +
          "Name=@Name,Des=@Des " +
          "WHERE ID=@Id";
        SqlCommand cmd = new SqlCommand(updateString, con);
        cmd.Parameters.AddWithValue("@Id", Id);
        cmd.Parameters.AddWithValue("@Name", Name);
        cmd.Parameters.AddWithValue("@Des", des);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }

    public static void DeleteProduct(int Id)
    {
        SqlConnection con = new SqlConnection(conString);
        string deleteString = "DELETE Products " +
          "WHERE ID=@Id";
        SqlCommand cmd = new SqlCommand(deleteString, con);
        cmd.Parameters.AddWithValue("@Id", Id);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }

}

Web.Config

<?xml version="1.0"?>

<configuration>
 <appSettings/>
 <connectionStrings/>
 <system.web>
  <pages>
   <controls>
    <add namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
    <add namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
   </controls>
  </pages>

  <compilation debug="true">
   <assemblies>
    <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>

  <authentication mode="Windows"/>

 </system.web>
</configuration>

Sql.txt

Products

Id Name Des

1 ProA FirstPro
2 ProB 2ndPro


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:120954次
    • 积分:1685
    • 等级:
    • 排名:千里之外
    • 原创:43篇
    • 转载:19篇
    • 译文:0篇
    • 评论:28条
    文章分类
    最新评论