呵呵,僅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 id="div1">
<ASP:GridView ID="GridVIEw1" runat="server" Height="300px" Width="200px">
</ASP:GridVIEw>
</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;
}
}