【转】GridView 加载空行并点击编辑每一个单元格
代码 <script runat="server">
protectedvoid Button1_Click(object sender, System.EventArgs e)
{
GridView1.DataSource = GetData();
GridView1.DataBind();
} protectedvoid Button2_Click(object sender, System.EventArgs e)
{
string s = String.Empty;
for (int i =; i <; i++)
{
for (int j =; j <; j++)
{
s = s +"<li>第 "+ i.ToString() +" 行第 "+ j.ToString() +" 列的值是:"+ Request.Form["txt"+ i.ToString() +"_"+ j.ToString()];
}
}
ret.Text = s;
// 以下代码只是为了实现在表格里面保留原来的值,如果不需要则可以删除。
GridView1.DataSource = GetData();
GridView1.DataBind();
} protectedvoid GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Data.DataRowView dv = (System.Data.DataRowView)e.Row.DataItem;
for (int i =; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("onclick", "showEdit("+ e.Row.RowIndex.ToString() +","+ i.ToString() +")");
e.Row.Cells[i].Text ="<input onblur='lostfocus(this)' name='txt"+ e.Row.RowIndex.ToString() +"_"+ i.ToString() +"' readonly='readonly' class='noborder' value='"+ dv[i].ToString() +"'/>";
}
}
} private System.Data.DataTable GetData()
{
System.Data.DataTable dt =new System.Data.DataTable();
for (int i =; i <; i++)
{
dt.Columns.Add(new System.Data.DataColumn("", typeof(System.String)));
} for (int i =; i <; i++)
{
dt.Rows.Add(dt.NewRow());
for (int j =; j <; j++)
{
dt.Rows[i][j] = Request.Form["txt"+ i.ToString() +"_"+ j.ToString()];
}
}
return dt;
} </script> <html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.noborder{border-width: 0px;margin:2px;}
.hasborder{border-width: 2px;}
</style> <script type="text/javascript">
function showEdit(r, c) {
document.forms[].elements["txt"+ r +"_"+ c].readOnly =false;
document.forms[].elements["txt"+ r +"_"+ c].className ='hasborder';
document.forms[].elements["txt"+ r +"_"+ c].select();
}
function lostfocus(o) {
o.className ='noborder'
o.readOnly =true;
}
</script> </head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" ShowHeader="false" OnRowDataBound="GridView1_RowDataBound">
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="加载表格"/>
<asp:Button ID="Button2" runat="server" Text="保存数据" OnClick="Button2_Click"/>
<asp:Label ID="ret" runat="server"></asp:Label>
</form>
</body>
</html>
【转】GridView 加载空行并点击编辑每一个单元格的更多相关文章
- 【转】Android循环滚动广告条的完美实现,封装方便,平滑过渡,从网络加载图片,点击广告进入对应网址
Android循环滚动广告条的完美实现,封装方便,平滑过渡,从网络加载图片,点击广告进入对应网址 关注finddreams,一起分享,一起进步: http://blog.csdn.net/finddr ...
- cesium加载gltf模型点击以及列表点击定位弹窗
前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 之 ...
- JS事件 加载事件(onload)注意:1. 加载页面时,触发onload事件,事件写在<body>标签内。 2. 此节的加载页面,可理解为打开一个新页面时。
加载事件(onload) 事件会在页面加载完成后,立即发生,同时执行被调用的程序. 注意:1. 加载页面时,触发onload事件,事件写在<body>标签内. 2. 此节的加载页面,可理解 ...
- gridview根据条件来改变行的颜色以及改变单元格的颜色。
gridview根据条件来改变行的颜色以及改变单元格的颜色. 通过在RowDataBound事件中写代码来实现,见代码. protected void GridView1_RowDataBound(o ...
- js实现点击修改按钮之后单元格变成可编辑状态
主要实现原理: 每一行有一个修改按钮 点击修改之后,获取行对象,通过行对象再获取行中单元格数组.然后把每一个单元格中的innerHTML替换成input输入框,并赋值value=原来单元格中的内容,鼠 ...
- Developer Express控件gridcontrol中gridView的某一个单元格是否可以自由输入
场景:在Developer Express控件gridcontrol中的gridView中,当医生开的临时医嘱的医嘱类型为"中草药","计价总量"单元格不可以自 ...
- 利用LruCache为GridView加载大量本地图片完整示例
MainActivity如下: package cc.testlrucache; import android.os.Bundle; import android.widget.GridView; i ...
- 用Volley让GridView加载网络图片
一.布局文件 总共两个布局文件,一个是GridView,还有一个是GridView的item,是NetworkImageView和TextView activity_main.xml <Rela ...
- ArcGIS API for JS4.7加载FeatureLayer,点击弹出信息并高亮显示
我加载的是ArcGIS Server本地发布的FeatureService,ArcGIS API for JS4.7记载FeatureLayer时,在二维需要通过代码启用WebGL渲染,在三维模式下, ...
随机推荐
- 【刷题】HDU 2222 Keywords Search
Problem Description In the modern time, Search engine came into the life of everybody like Google, B ...
- 【刷题】BZOJ 4816 [Sdoi2017]数字表格
Description Doris刚刚学习了fibonacci数列.用f[i]表示数列的第i项,那么 f[0]=0 f[1]=1 f[n]=f[n-1]+f[n-2],n>=2 Doris用老师 ...
- BZOJ 2668: [cqoi2012]交换棋子
2668: [cqoi2012]交换棋子 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1112 Solved: 409[Submit][Status ...
- AtCoder Grand Contest 003
AtCoder Grand Contest 003 A - Wanna go back home 翻译 告诉你一个人每天向哪个方向走,你可以自定义他每天走的距离,问它能否在最后一天结束之后回到起点. ...
- 【BZOJ2024】舞会(动态规划,容斥,高精度)
[BZOJ2024]舞会(动态规划,容斥,高精度) 题面 BZOJ 洛谷 题解 这种关系显然要先排序才不会不想影响. 设\(f[i][j]\)表示前\(i\)个女生中,选了\(j\)个女生配对,并且女 ...
- 【uoj131】 NOI2015—品酒大会
http://uoj.ac/problem/131 (题目链接) 题意 给出一个字符串,每个后缀有一个权值${a_i}$,这些后缀两两之间存在公共前缀.问能够组成长度从0~n-1的公共前缀的后缀的方案 ...
- JS的强制类型转换
将值从一种类型转换为另一种类型通常称为类型转换,这是显式的情况,隐式的情况称为强制类型转换. JavaScript中的强制类型转换总是返回标量基本类型值,如字符串.数字和布尔值,不会返回对象和函数. ...
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1(zz)
android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1 http://blog.cs ...
- 洛谷P3994 Highway(树形DP+斜率优化+可持久化线段树/二分)
有点类似NOI2014购票 首先有方程$f(i)=min\{f(j)+(dep_i-dep_j)*p_i+q_i\}$ 这个显然是可以斜率优化的... $\frac {f(j)-f(k)}{dep_j ...
- linux操作系统位数
方法1:getconf LONG_BIT 查看 如下例子所示: 32位Linux系统显示32, 64位Linux系统显示64.最简单.快捷的方法. [root@DB-Server ~]# getcon ...