当前位置:主页>net>文章内容
ASP.NET技巧:使Div内内容可编辑
来源: 作者: 发布时间:2007-04-05  

呵呵,仅IE有效:)
前台代码:
<%@ 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>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="width:600px;height:400px;" id="div1">
        <asp:GridView ID="GridView1" runat="server" Height="300px" Width="200px">
        </asp:GridView>
        &nbsp;</div>
    <script language="javascript" type="text/javascript">
       document.getElementById("div1").contentEditable = true;
       document.execCommand('2D-Position', true, true);
    </script>
    </form>
</body>
</html>后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.Style.Add("position", "absolute");
            GridView1.DataSource = GetDataSet();
            GridView1.DataMember = "testtable";
            GridView1.DataBind();
        }
    }

    private DataSet GetDataSet()
    {
        DataTable dt = new DataTable("testtable");
        dt.Columns.Add("Col1", typeof(int));
        dt.Columns.Add("Col2", typeof(string));
        dt.Columns.Add("Col3", typeof(string));
        dt.Columns.Add("Col4", typeof(string));

        DataRow dr;

        for (int i = 0; i < 10; i++)
        {
            dr = dt.NewRow();
            dr[0] = i;
            dr[1] = "Val" + i.ToString();
            dr[2] = "Val" + i.ToString();
            dr[3] = "Val" + i.ToString();
            dt.Rows.Add(dr);
        }

        DataSet ds = new DataSet();
        ds.Tables.Add(dt);
        return ds;
    }
}


 
上一篇:初谈ADO.NET中利用DataAdapter进行数据操作   下一篇:ASP与ASP.NET互通COOKIES的一点经验
 
  相关文章
·初谈ADO.NET中利用DataAdapter进行数据
·ASP与ASP.NET互通COOKIES的一点经验
·ASP.NET 2.0 中的窗体身份验证
·ASP.NET技巧:教你制做Web实时进度条
·如何在C#中播放AVI短片并使背景透明
·第一次用.net2.0 LOGIN登陆控件的困惑
·在.NET中利用委托实现窗体间通信
·ASP.NET入门随想之检票的老太太
·ASP.NET2.0数据库入门之SqlDataSource
·ASP.NET实现文件的在线压缩和解压缩
·Visual C#2005快速入门之switch语句
·用.NET 2.0压缩/解压功能处理大型数据
 
【关闭窗口】
推荐本站资源
最新文章