locked
Get detailsview control values using jquery RRS feed

  • Question

  • User-809753952 posted

    I have a detailsview inside a Ajax ModalPopup Extender.

    There are some controls like labels, textbox, dropdownlist and hidden fields inside the detailsview's itemtemplate.

    How can I set and get the values of these controls using jQuery.

    Wednesday, October 12, 2016 3:35 PM

Answers

  • User-1838255255 posted

    Hi mnmhemaj,

    According to your description , you want get control's value in dialog by jquery . I make a sample for your reference , I put some controls in detailsview ,then use jquery by ID and get value.

    Sample Code:

    <head runat="server">
        <title></title>
        <script src="Scripts/jquery-1.10.2.js"></script>
        <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
        <link rel="stylesheet" href="/resources/demos/style.css" />
        <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
        <script>
            $(function(){
                $("#Box").dialog({
                })
            })
            function hhh() {
                var text = $("#ctl04_Label1").text();
                var text1 = $("#ctl04_Label2").text();
                var value = $("#ctl04_TextBox1").val();
                alert("First Field : " + text + "Second Field: : " + text + "State : "+value);
                return false;
            }
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <div id="Box">
                    <asp:DetailsView runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataKeyNames="MigrationId,ContextKey" DataSourceID="SqlDataSource1">
                        <Fields>
                            <asp:BoundField DataField="MigrationId" HeaderText="MigrationId" ReadOnly="True" SortExpression="MigrationId" />
                            <asp:BoundField DataField="ContextKey" HeaderText="ContextKey" ReadOnly="True" SortExpression="ContextKey" />
                            <asp:BoundField DataField="ProductVersion" HeaderText="ProductVersion" SortExpression="ProductVersion" />
                        <asp:TemplateField>
                            <ItemTemplate>
                                 <asp:Label ID="Label1" runat="server"  Text="">Hello,</asp:Label>
                                <asp:Label ID="Label2" runat="server" Text="">Word!</asp:Label>
                                <asp:TextBox ID="TextBox1" runat="server" Text="DOWN!"></asp:TextBox>
                            <asp:Button runat="server" Text="Button" OnClientClick="return hhh()" />
                            </ItemTemplate>
                        </asp:TemplateField>
                        </Fields>
                    </asp:DetailsView>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MoviesConnectionString %>" SelectCommand="SELECT * FROM [__MigrationHistory]"></asp:SqlDataSource>
                </div>
            </div>
        </form>
    </body>
    

    Screenshot:

    Best Regards,

    Eric Du

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 13, 2016 10:31 AM