当前位置:编程学习 > C#/ASP.NET >>

js 获取 repeater 每行值

 例:

asp:repeater id="RptOrderTicket" runat="server" enableviewstate="False" onitemcommand="RptOrderTicket_ItemCommand"
            onitemdatabound="RptOrderTicket_ItemDataBound">
                    <ItemTemplate>
                        <tr onmouseover="this.style.background='#fff9e9'" onmouseout="this.style.background=''">
                           <td> <asp:CheckBox id="cbx" runat="server"></asp:CheckBox>  <asp:Label runat="server" id="lbl" Text='<%#Eval("ofmuId") %>'></asp:Label> 
      </td>                      
   </tr>
                    </ItemTemplate>
       </asp:repeater>     

如果   CheckBox 是选中,就获取对应  Label 的值              js+repeater --------------------编程问答-------------------- 参考一下:http://blog.csdn.net/chinacsharper/article/details/10000983 --------------------编程问答--------------------
引用 1 楼 guwei4037 的回复:
参考一下:http://blog.csdn.net/chinacsharper/article/details/10000983




找不开? --------------------编程问答--------------------
引用 2 楼 qtvb1987 的回复:
Quote: 引用 1 楼 guwei4037 的回复:

参考一下:http://blog.csdn.net/chinacsharper/article/details/10000983




找不开?



打开了 --------------------编程问答--------------------
引用 1 楼 guwei4037 的回复:
参考一下:http://blog.csdn.net/chinacsharper/article/details/10000983





我好像获取不到repeater里的值 --------------------编程问答-------------------- 用JQuery关键是看最终生成的html的结构,根据具体的特征进行绑定。
后台:
if (!Page.IsPostBack)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ofmuId", typeof(string));

                dt.Rows.Add("1000");
                dt.Rows.Add("121212");

                this.Repeater1.DataSource = dt;
                this.Repeater1.DataBind();
            }

页面:
 <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:CheckBox ID="cbx" runat="server"></asp:CheckBox>
                        <asp:Label runat="server" ID="lbl" Text='<%#Eval("ofmuId") %>'></asp:Label>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

JS代码:
  $(function () {
            $("table").find("tr td input[type=checkbox]").each(function () {
                $(this).bind("click", function () {
                    if (this.checked) {
                        var id = $(this).parent().parent().find("span[id*=lbl]").text();
                        alert(id);
                    }
                });
            });
        });

效果:
--------------------编程问答-------------------- 如LS的,直接用Firebug之类的浏览器调试工具看实际显示出来的html,然后用js去抓 --------------------编程问答--------------------
引用 5 楼 guwei4037 的回复:
用JQuery关键是看最终生成的html的结构,根据具体的特征进行绑定。
后台:
if (!Page.IsPostBack)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ofmuId", typeof(string));

                dt.Rows.Add("1000");
                dt.Rows.Add("121212");

                this.Repeater1.DataSource = dt;
                this.Repeater1.DataBind();
            }

页面:
 <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        <asp:CheckBox ID="cbx" runat="server"></asp:CheckBox>
                        <asp:Label runat="server" ID="lbl" Text='<%#Eval("ofmuId") %>'></asp:Label>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

JS代码:
  $(function () {
            $("table").find("tr td input[type=checkbox]").each(function () {
                $(this).bind("click", function () {
                    if (this.checked) {
                        var id = $(this).parent().parent().find("span[id*=lbl]").text();
                        alert(id);
                    }
                });
            });
        });

效果:



谢谢
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,