简体   繁体   中英

How to access the value of the Label present inside Datagrid asp.net using jquery?

 <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>

How can i access this Status Label value using jquery Please help

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

Will the above code work?

EDIT : Tried using this code as suggested

 $(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;
                }


            }

        });
    }); 

I am not able to fetch the status but

在此处输入图片说明

it will not work. becoz label is not direct child of datagrid1 . you can use like this

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

please refer about children api in jquery:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM