【问题标题】:How to access the value of the Label present inside Datagrid asp.net using jquery?如何使用 jquery 访问 Datagrid asp.net 中存在的标签的值?
【发布时间】:2012-10-07 23:42:18
【问题描述】:
 <asp:DataGrid ID="datagrid1" runat="server" AutoGenerateColumns="False" Width="100%"
                    DataKeyField="Expr1" OnItemCommand="datagrid1_ItemCommand" EmptyDataText="No Records Found" 
                    >
                    <HeaderStyle BackColor="#2E882E" Font-Bold="True" ForeColor="#FFFFCC" HorizontalAlign="Left" />
                    <Columns>
                        <asp:TemplateColumn HeaderText="">
                            <ItemTemplate>
                                <table>
                                    <tr>
                                         <td class="style1">
<asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Status") %>'></asp:Label>
                                        </td>
  </tr>
                                </table>
                            </ItemTemplate>
                        </asp:TemplateColumn>
                    </Columns>
                </asp:DataGrid>

如何使用jquery 访问此状态标签值请帮助

   var DataGrid1 = $("<%=datagrid1.ClientID %>");
var status = $(DataGrid1).children("lblStatus").get(0).innerHTML;

上面的代码能用吗?

编辑:按照建议尝试使用此代码

 $(document).ready(function () {
        $('.vini').click(function () {
            //var status = $("#<%=ddlstatus.ClientID%>").val();
            var DataGrid1 = $("#<%=datagrid1.ClientID %>");
              var status =$(DataGrid1).find("txtStatDesc").html();




            if (status == 'Sent') {
                var _Action = confirm('Do you really want to cancel this payment ? All pending money will be available in the retention account of the contractor ');
                if (_Action) {
                    $.blockUI({ css: {
                        border: 'none',
                        padding: '15px',
                        backgroundColor: '#000',
                        '-webkit-border-radius': '10px',
                        '-moz-border-radius': '10px',
                        opacity: .5,
                        color: '#fff'
                    }
                    });
                    return true;
                }
                else {
                    return false;
                }


            }

        });
    }); 

我无法获取状态,但是

【问题讨论】:

    标签: c# jquery asp.net datagrid


    【解决方案1】:

    它不会工作。因为label 不是datagrid1 的直子。 你可以这样使用

     var DataGrid1 = $("<%=datagrid1.ClientID %>");
     $("#"+DataGrid1).find("label").html();
    

    请参考jquery中的children api:

    http://api.jquery.com/children/

    【讨论】:

    • 您的代码也无法正常工作,因为您错过了网格选择器$("#&lt;%=datagrid1.ClientID %&gt;")中的尖锐符号@
    • 能否提供选择器的链接?
    • @YuriyRozhovetskiy:你能告诉我选择器有什么问题吗?
    • @YogeshWaran,请参考 jquery 中的 id 选择器;):api.jquery.com/id-selector
    • 我应该把这段代码放在哪里,因为我必须在我的数据网格中存在的取消按钮点击中调用它
    猜你喜欢
    • 1970-01-01
    • 2011-10-24
    • 2017-06-26
    • 1970-01-01
    • 2012-09-28
    • 1970-01-01
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多