<asp:Repeater ID="rptfindData" runat="server">
<HeaderTemplate>
<tr>
<td>repeater中的自增</td>
<td>ID</td>
<td>Name</td>
<td>Sex</td>
<td>operation</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Container.ItemIndex+1 %></td>
<td><%#Eval("ID") %></td>
<td>
<label id="lbl-Name-<%# Container.ItemIndex+1 %>" style="display: block"><%#Eval("Name") %></label>
<input id="txt-Name-<%# Container.ItemIndex+1 %>" type="text" value='<%#Eval("Name") %>' style="display: none;"/>
</td>
<td>
<label id="lbl-Sex-<%# Container.ItemIndex+1 %>" style="display: block"> <%#Eval("Sex").ToString() == "1" ? "男" : "女" %></label>
<div id="div-sex-<%# Container.ItemIndex+1 %>" style="display: none">
<%--<asp:RadioButton ID="male" Checked="True" GroupName="Gender" runat="server" Text="男" />
<asp:RadioButton ID="female" GroupName="Gender" runat="server" Text="女" />--%>
<input id="male-<%# Container.ItemIndex+1 %>" type="radio" value="1" name="gender-<%# Container.ItemIndex+1 %>" <%#Eval("Sex").ToString() == "1" ? "checked='checked'" : "" %> />男
<input id="female-<%# Container.ItemIndex+1 %>" type="radio" value="2" name="gender-<%# Container.ItemIndex+1 %>" <%#Eval("Sex").ToString() == "2" ? "checked='checked'" : "" %> />女
</div>
<%--<input id="txt-Sex-<%# Container.ItemIndex+1 %>" type="text" value='<%#Eval("Sex") %>' style="display: none"/>--%>
</td>
<td>
<label id="lbl-update-<%# Container.ItemIndex+1 %>" style="display: block" onclick="displayText(<%# Container.ItemIndex+1 %>)">update</label>
<label id="lbl-save-<%# Container.ItemIndex+1 %>" style="display: none" onclick="displayLabel(<%# Container.ItemIndex+1 %>,<%#Eval("ID") %>)">save</label>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
</form>
</body>
</html>
<script type="text/javascript">
function displayText(id) {
$("#lbl-Name-" + id).css("display", "none");
$("#txt-Name-" + id).css("display", "block");
$("#lbl-Sex-" + id).css("display", "none");
$("#txt-Sex-" + id).css("display", "block");
$("#div-sex-" + id).css("display", "block");
$("#lbl-update-" + id).css("display", "none");
$("#lbl-save-" + id).css("display", "block");
}
function displayLabel(id, dataId) {
debugger;
$("#lbl-Name-" + id).css("display", "block");
$("#txt-Name-" + id).css("display", "none");
$("#lbl-Sex-" + id).css("display", "block");
$("#txt-Sex-" + id).css("display", "none");
$("#div-sex-" + id).css("display", "none");
$("#lbl-update-" + id).css("display", "block");
$("#lbl-save-" + id).css("display", "none");
var name = $("#txt-Name-" + id).val();
// var sexPD = $('').checked;
//var sex;
//if (sexPD) {
// sex = 1;
//} else {
// sex = 2;
//}
var sex = $("input:radio[name='gender-" + id + "']:checked").val();
//var sex = $("#txt-Sex-" + id).val();
//保存数据
$.ajax({
url: "/GridViewDataASHX.ashx",
type: "post",
async: false,
cache:false,
data: {
"name": name,
"sex": sex,
"id":dataId
},
success: function (data) {
if (data > 0) {
alert("成功!");
window.location.href = window.location.href;
} else {
alert("失败!");
}
}
});
}

是否还有更好的实现方式呢?

使用repeater实现gridview的功能的更多相关文章

  1. Repeater 和 GridView 添加序列号

    <tr><asp:Repeater ID="rptOfBrowerInfo" runat="server" >    <Heade ...

  2. aspnetpager+repeater+oracle实现分页功能

    一.设计原理阐述 数据查询分页,这个功能相信大家都很熟悉,通过数据库或其它数据源进行查询操作后,将获得的数据显示到界面上,但是由于数据量太大,不能一次性完全的显示出来,就有了数据分页的需求.这个需求在 ...

  3. asp.net 中Repeater和Gridview的区别

             Griview:              优点:1.GridView是从WebControl派生出来的,拥有WebControl样式属性,自身会被解析为table,其中的每一行会被 ...

  4. 分享一个我的JavaScript版GridView多功能表格

    GridView是什么? GridView是由Mr.Co开发的一套开源的多功能表格插件,主要用于让页面开发者在开发中节省拼接Table表格和操作Table表格相关复杂操作的开发成本与时间.开发人员可以 ...

  5. Repeater和Gridview前台显示行号的方法

    Repeater : Container.ItemIndex (行号从零开始,如果想改为从1开始,那么可以将以上的代码改为Container.ItemIndex + 1),见下示例: <asp: ...

  6. GridView分页功能的实现

    当GridView中显示的记录很多的时候,可以通过GridView的分页功能来分页显示这些记录.如果GridView是直接绑定数据库,则很简单:将"启动分页"打勾即可. 如果是用代 ...

  7. Repeater嵌套gridview

    前台:<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSour ...

  8. 【DevExpress v17.2新功能预告】增强ASP.NET GridView的功能

    在下一个主要版本v17.2中,我们将为DevExpress ASP.NET GridView添加一些优秀的新功能.在本文中为大家介绍的所有功能都可用于 GridView的ASP.NET WebForm ...

  9. 自己写的一个ASP.NET服务器控件Repeater和GridView分页类

    不墨迹,直接上代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...

随机推荐

  1. PostgreSQL:安装

    官网地址:https://www.postgresql.org/ 安装文件下载地址:http://www.enterprisedb.com/products-services-training/pgd ...

  2. java io读书笔记(2)什么是stream

    什么是stream?stream就是一个长度不确定的有序字节序列. Input streams move bytes of data into a Java program from some gen ...

  3. iOS8中用UIVisualEffectView实现高斯模糊视图(毛玻璃效果)

    UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; UIVisualEffectView *vi ...

  4. JSP out乱码

    在form method="post" 写post 在接受页面jsp代码前面加request.setCharacterEncoding("UTF-8");

  5. Topcoder SRM 597

    妈蛋第一场tc就掉分,提交了第一个题的时候就注定悲剧要发生了,妈蛋没考虑0就直接%了,真的是人傻见识又少,第二题最后有了一点思路,没时间写了,可能也不是很准确,第三题想了小会儿效果为0! 然后第一题傻 ...

  6. 使用PHP发送邮件

    使用封装SMTP协议的邮件类 使用PEAR扩展中的Mail类,功能强大:可以支持纯文本.HTML格式的邮件:各字段都可设置编码,正确配置不会出现中文乱码情况:可以支持附件等等. 在服务器可以使用 pe ...

  7. 【py网页】urlopen的补充,完美

    urllib 是 python 自带的一个抓取网页信息一个接口,他最主要的方法是 urlopen(),是基于 python 的 open() 方法的.下面是主要说明: 1 urllib.urlopen ...

  8. yii2表关联实例

    yii2表关联 1.两张表关联,以“商品表关联品牌表”为例 控制器中: $goods_model=new Goods(); $goods_info=$goods_model::find()->j ...

  9. 一个容易被忽略的ReportingService超时问题

    我们在使用Sql Server Reporting Service开发报表的时候,经常会遇到报表超时的问题,报表超时的原因有很多,也有很多地方可以设置报表的超时时间,比如在报表中的数据源(dataso ...

  10. 5 Best Automation Tools for Testing Android Applications

    Posted In | Automation Testing, Mobile Testing, Software Testing Tools   Nowadays automated tests ar ...