今天费了很大的劲儿才搞定!下面贴出代码和总结:

1.首先是前台代码:

<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="CategoryList.aspx.cs" Inherits="Bridgetree.Admin.CategoryList" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script language=javascript> function edit(c_id) {/*此处的c_id为某一控件对象,因为传入的值为this*/ var lb_Edit_ID = c_id.id;/*取控件的id属性值*/
var ids = lb_Edit_ID.substring(lb_Edit_ID.lastIndexOf("_") + 1, lb_Edit_ID.length);/*获取数据库的ID字段*/
var CategoryID = $("span[ID='lbl_CategoryID_" + ids + "']").text();
/*根据id取文本值。
注:
  • text() - 设置或返回所选元素的文本内容(即设置或获取标签内的文本)
  • html() - 设置或返回所选元素的内容(包括 HTML 标记)
  • val() - 设置或返回表单字段的值(即设置或获取控件的文本)
  • 详情点击
*/

            var Category = $("span[ID='lbl_Category_" + ids+ "']").text();
/*alert($("#lbl_Category_" + ids).text());*/
var HourlyCost = $("span[ID='lbl_HourlyCost_" + ids + "']").text();
var BillingRate = $("span[ID='lbl_BillingRate_" + ids + "']").text(); $("#hf_CategoryID").val(CategoryID);/*设置控件的文本*/
$("#tb_Category").val(Category);
$("#tb_HourlyCost").val(HourlyCost);
$("#tb_BillingRate").val(BillingRate); /*var rate = document.getElementById("rate_" + id) rate.readOnly = false;
rate.style.backgroundColor = "white" e = document.getElementById("BtnEdit_" + id)
e.disabled = true; e = document.getElementById("BtnUpd_" + id)
e.disabled = false; rate.focus();*/
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server" ClientIDMode="Static">
<table id="conversionTable" class="tableCommon table-hover" width="100%">
<asp:Repeater ID="rpt_CategoryList" runat="server" OnItemDataBound="rpt_CategoryList_ItemDataBound">
<HeaderTemplate>
<tr>
<th>Category</th>
<th>HourlyCost($)</th>
<th>BillingRate</th>
<th>Edit</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Label runat="server" ID="lbl_Category" Text='<%#Eval("Category1") %>'></asp:Label><asp:Label runat="server" ID="lbl_CategoryID" style="display:none;" Text='<%#Eval("CategoryID") %>'></asp:Label></td>
<td><asp:Label runat="server" ID="lbl_HourlyCost" Text='<%#Eval("HourlyCost") %>'></asp:Label></td>
<td><asp:Label runat="server" ID="lbl_BillingRate" Text='<%#Eval("BillingRate")%>'></asp:Label></td>
<td>
<asp:LinkButton runat="server" ID="lb_Edit" href="#TB_inline?height=300&width=400&inlineId=myOnPageContent" Class="thickbox" OnClientClick="edit(this);">Edit</asp:LinkButton></td> /*此处需要注意:该标签会先执行onclick事件,然后再去执行href*/
</tr>
</ItemTemplate>
</asp:Repeater> </table>
<div id="myOnPageContent" style="display:none;">
<input type="hidden" id="hf_CategoryID" runat="server"/>
<p>Category:<input id="tb_Category" readonly="true" /></p>
<p>HourlyCost($):<input id="tb_HourlyCost"/></p>
<p>BillingRate($):<input id="tb_BillingRate"/></p>
<asp:Button runat="server" ID="btn_Save" Width="50px" Text="Save" OnClick="btn_Save_Click"/>
</div> </asp:Content>

2.后台代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace Bridgetree.Admin
{
public partial class CategoryList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.rpt_CategoryList.DataSource = PCS.DAL.EF.Repository.GetInstance().GetCategoryList();
this.rpt_CategoryList.DataBind();
} protected void rpt_CategoryList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)//**
{
Label lbl_CategoryID = e.Item.FindControl("lbl_CategoryID") as Label;
Label lbl_Category = e.Item.FindControl("lbl_Category") as Label;
Label lbl_HourlyCost = e.Item.FindControl("lbl_HourlyCost") as Label;
Label lbl_BillingRate = e.Item.FindControl("lbl_BillingRate") as Label;
LinkButton lb_Edit = e.Item.FindControl("lb_Edit") as LinkButton;
if (lbl_CategoryID != null && lbl_Category != null && lbl_HourlyCost != null && lbl_BillingRate != null && lb_Edit != null)
{
/*此处ID在被解释成静态之后会变成控件的name和id属性,
* 而且嵌套在模板页中的控件会自动添加上<content>的ID值(例如:<input name="ctk100$BodyContent$RealName" id="BodyContent_RealName" />)
* ,若套在模板页中需要在<content>中添加ClientIDMode="Static",这样ID就只对应静态控件的ID属性*/
lbl_CategoryID.ID = "lbl_CategoryID_" + lbl_CategoryID.Text;
lbl_Category.ID = "lbl_Category_" + lbl_CategoryID.Text;
lbl_HourlyCost.ID = "lbl_HourlyCost_" + lbl_CategoryID.Text;
lbl_BillingRate.ID = "lbl_BillingRate_" + lbl_CategoryID.Text;
lb_Edit.ID = "lb_Edit_" + lbl_CategoryID.Text;
//lb_Edit.Attributes.Add("onclientclick", "edit(" + lbl_CategoryID.Text + ")");
}
}
}
}
}

3.最终效果

4.用到的文件:

http://files.cnblogs.com/ethanwill/jquery-tanchucengxiaoguoone.rar

最新文章

  1. Java学习笔记之JNDI(六)
  2. Linux下介绍一款不错的HTML编辑器
  3. MVC高级编程+C#高级编程
  4. PYTHON学习之路_PYTHON基础(6)
  5. HTML 学习笔记 JavaScript (对象)
  6. 记忆用户设置-提升程序的体验VB/C#
  7. javabean与map互转
  8. 二分多重匹配(HDU5093)
  9. [转]C语言文件操作
  10. HTTP协议请求方式: 中GET、POST和HEAD的介绍以及错误提示码
  11. hibernate[版本四]知识总结
  12. linux read 用法
  13. mssql字符串分割后的值,把表中不存在的插入表中
  14. 基于visual Studio2013解决算法导论之007优先队列(堆实现)
  15. K&amp;amp;R练习题6-1统计关键词出现的次数
  16. js 设为首页、加入收藏
  17. Python中模块之hashlib&amp;hmac的讲解
  18. 潭州课堂25班:Ph201805201 django 项目 第三十六课 后台文章管理(课堂笔记)
  19. 【Vue】v-if与v-show的区别
  20. Atitit 项目源码的架构,框架,配置与环境说明模板 规范 标准化

热门文章

  1. U当家U盘启动盘制作教程
  2. 全国省市级联数据sql语句 mysql版
  3. word-wrap同word-break的区别(转)
  4. PHP扩展编写示例
  5. 了解实时媒体的播放(RTP/RTCP 和 RTSP)
  6. comm命令——
  7. Java多态的体现之继承
  8. Shell编程学习---第五篇:Shell的输入和输出
  9. Nginx+Keepalived 做负载均衡器
  10. [ECNU 1624] 求交集多边形面积