【转】GridView 加载空行并点击编辑每一个单元格

 1 代码
2
3 <script runat="server">
4 protectedvoid Button1_Click(object sender, System.EventArgs e)
5 {
6 GridView1.DataSource = GetData();
7 GridView1.DataBind();
8 }
9
10 protectedvoid Button2_Click(object sender, System.EventArgs e)
11 {
12 string s = String.Empty;
13 for (int i =0; i <5; i++)
14 {
15 for (int j =0; j <5; j++)
16 {
17 s = s +"<li>第 "+ i.ToString() +" 行第 "+ j.ToString() +" 列的值是:"+ Request.Form["txt"+ i.ToString() +"_"+ j.ToString()];
18 }
19 }
20 ret.Text = s;
21 // 以下代码只是为了实现在表格里面保留原来的值,如果不需要则可以删除。
22 GridView1.DataSource = GetData();
23 GridView1.DataBind();
24 }
25
26 protectedvoid GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
27 {
28 if (e.Row.RowType == DataControlRowType.DataRow)
29 {
30 System.Data.DataRowView dv = (System.Data.DataRowView)e.Row.DataItem;
31 for (int i =0; i < e.Row.Cells.Count; i++)
32 {
33 e.Row.Cells[i].Attributes.Add("onclick", "showEdit("+ e.Row.RowIndex.ToString() +","+ i.ToString() +")");
34 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() +"‘/>";
35 }
36 }
37 }
38
39 private System.Data.DataTable GetData()
40 {
41 System.Data.DataTable dt =new System.Data.DataTable();
42 for (int i =0; i <5; i++)
43 {
44 dt.Columns.Add(new System.Data.DataColumn("", typeof(System.String)));
45 }
46
47 for (int i =0; i <5; i++)
48 {
49 dt.Rows.Add(dt.NewRow());
50 for (int j =0; j <5; j++)
51 {
52 dt.Rows[i][j] = Request.Form["txt"+ i.ToString() +"_"+ j.ToString()];
53 }
54 }
55 return dt;
56 }
57
58 </script>
59
60 <html xmlns="http://www.w3.org/1999/xhtml">
61 <head id="Head1" runat="server">
62 <title></title>
63 <style type="text/css">
64 .noborder{border-width: 0px;margin:2px;}
65 .hasborder{border-width: 2px;}
66 </style>
67
68 <script type="text/javascript">
69 function showEdit(r, c) {
70 document.forms[0].elements["txt"+ r +"_"+ c].readOnly =false;
71 document.forms[0].elements["txt"+ r +"_"+ c].className =‘hasborder‘;
72 document.forms[0].elements["txt"+ r +"_"+ c].select();
73 }
74 function lostfocus(o) {
75 o.className =‘noborder‘
76 o.readOnly =true;
77 }
78 </script>
79
80 </head>
81 <body>
82 <form id="form1" runat="server">
83 <asp:GridView ID="GridView1" runat="server" ShowHeader="false" OnRowDataBound="GridView1_RowDataBound">
84 </asp:GridView>
85 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="加载表格"/>
86 <asp:Button ID="Button2" runat="server" Text="保存数据" OnClick="Button2_Click"/>
87 <asp:Label ID="ret" runat="server"></asp:Label>
88 </form>
89 </body>
90 </html>

【转】GridView 加载空行并点击编辑每一个单元格

时间: 2024-08-08 18:38:36

【转】GridView 加载空行并点击编辑每一个单元格的相关文章

GridView加载大量图片卡顿问题

1  在异步加载之前的代码的和普通加载代码一样,只需要在GirdView的Adapter的public View getView(int position, View convertView, ViewGroupparent)方法使用异步加载的方式返回ImageView. 2  如果能把加载过的图片给缓存起来,而不用每次都从sd卡上读取,这样效率应该会提高不少.所以可以先建一个缓存类,MemoryCache,为了能尽可能缓存,又尽可能的不抛出OOM的异常,可以使用SoftReference<Bi

关于iOS UIWebView 加载网页,点击网页内某些控件导致 Application &#39;UIKitApplication:xxx.xxx.xxx&#39; was killed by jetsam.

问题:公司用的腾讯问卷系统,内嵌在我们应用或游戏的自定义UIWebView里面展示,发现在iOS 10 以下系统,点击圆形勾选框 会大概率出现闪退. 通过联调发现:报了这样一个警告Application 'UIKitApplication:xxx.xxx.xxx' was killed by jetsam. 然后没有更多的信息了. (连接真机调试,当发生闪退的时候,设备会同时跟Xcode断开连接,没有更多的错误堆栈,另外设备也没有记录下更多的Crash log 提供定位.) 最后从以下获取到近似

C# DataGridView点击Enter键切换单元格

#region 将ENTER键转换为TAB protected override void OnKeyUp(System.Windows.Forms.KeyEventArgs e) { base.OnKeyUp(e); if (e.KeyCode == System.Windows.Forms.Keys.Enter) { e.Handled = true; System.Windows.Forms.SendKeys.Send("{TAB}"); } } protected overri

Android中webview加载网页无法点击或滚动

由于工作忙,很久没写博客了,今天就先来一篇吧,这也是项目中遇到的问题. 如题,webview加载网页,但是网页内容无法滚动和点击,且网页内容也没有正常全部展示,主要是因为没有正确setting而已,解决访求如下: WebSettings s = webview.getSettings(); s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); s.setUseWideViewPort(true); s.setLoadW

利用LruCache为GridView加载大量本地图片完整示例

MainActivity如下: package cc.testlrucache; import android.os.Bundle; import android.widget.GridView; import android.app.Activity; public class MainActivity extends Activity { private GridView mGridView; private GridViewAdapter mGridViewAdapter; @Overri

viewpager+fragment的懒加载实现微信点击和滑动切换功能(切换效果)

前言 1.从上一片文章之后已经半年没有写文章了,那篇文章之后公司进入疯狂的加班,一直到放年假.年后回来之后换了一家创业公司之后,然后又进入疯狂的加班(≧﹏ ≦) -所以一直都没有写文章(其实这都是借口⊙﹏⊙).现在公司没有那么忙了,也该把文章捡起来了,这毕竟是百利有一害的事(一害:费时间). 2.这半年里除了对代码的热情更加高涨(虽然它总是虐我千百遍(≧﹏ ≦) ),还深深的中了爬山的毒,对于年轻的我来说,爬山让我明白了许多.懂得了许多,也锻炼了我的身体.对于程序员来说身体是非常重要的,大家在周

Android GridView加载大量图片时出现OOM情况

最近写的一个应用涉及到使用GridView显示图片,当使用BaseAdapter传统的的实现时,在真机上快速滚动时会出现OOM情况. 一个临时性的解决方案就是改动图片尺寸,减小内存.这种方法简单却不安全.如果图片够多,也存在依然OOM的情况. 一个有效的方法就是使用异步加载. 获取应用程序最大可用内存: int maxMemory = (int) Runtime.getRuntime().maxMemory(); 还可以使用convertView 回收视图,结合使用ViewHolder模式,提高

Android设置Notification从网络中加载图片,解决点击无法消失的bug

Notification的构造函数中只支持使用资源文件的图片作为图片,但是如果我们想用网络中的图片怎么办呢. 我们知道,给Notification设置内容的时候调用的是setLatestEventInfo方法,当我们点击去看该方法的时候,所有的结果都一目了然了. public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent con

Jqeury Mobile实战之切屏效果以及屏幕滚动到底端加载更多和点击切换更多

http://blog.csdn.net/q718330882/article/details/46120691 //页面滚动到底部加载更多事件 $( window ).scroll(function(){ if ( $(window).scrollTop() >= $(document).height() - $(window).height() ) { var strAppend = ''; for( var i = 1; i < 10; i++ ) { strAppend += '<