呵呵,仅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;
}
}
新闻热点
疑难解答
图片精选