-1

i have written a code in JavaScript, i dont know wether it is correct or not bocause i havent attached js in my code.. this is my code :

I want to do such that a window appears on the button click of Details whose ID is 'Details' and on the button click, there also appears the record agains that id.. Is this written js is correctly written or not? will this js accomplish the above task?

<script type="text/javascript">
    function viewProfile(index)
    {
    var GridID = document.getElementById("PersonGridView");
    var row=GridID.rows[parseInt(index)+1];
    var id = document.getElementById("Details");
    window.open('detailsid'+row);
    }

    </script>

<div>
        <asp:GridView ID="PersonGridView" runat="server" BackColor="White" 
            BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
            ForeColor="Black" GridLines="Vertical" AutoGenerateColumns="false" onrowdatabound="PersonGridView_RowDataBound" 
            >
            <RowStyle BackColor="#F7F7DE" />

            <Columns>
                <asp:BoundField HeaderText="First Name" DataField="FirstName" />
                <asp:BoundField HeaderText="Last Name" DataField = "LastName" />
                <asp:BoundField HeaderText="HomePhoneNumber" DataField="HomePhoneNumber" />
                <asp:TemplateField HeaderText="ViewDetails">
                <ItemTemplate>
                <asp:Button ID="Deatils" runat="server" Text="Details" />
                </ItemTemplate>    

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Actions">
                <ItemTemplate>
                <asp:Button ID="Modify" runat="server" Text="Modify" />
                <asp:Button ID="Delete" runat="server" Text="Delete" />

                </ItemTemplate>
                </asp:TemplateField>


            </Columns>


            <FooterStyle BackColor="#CCCC99" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
    </div>
2
  • 1
    What happened when you tested it? You ask if it will work, but that's something a simple test on your part could have told you. I don't intend to be rude, but this post just seems like you're asking someone to do your work for you. As your code stands now it will not work. Unit test it and come back with some more specific questions (if you still have them). Commented Feb 22, 2011 at 12:28
  • 2
    You would have a much better chance of getting help if you posted your example as a jsfiddle.net link instead of attaching an ASP file to a question about JavaScript. Commented Feb 22, 2011 at 12:34

1 Answer 1

0

The comments below your question are valid. A little more information would be useful. I can however point out one problem in your code. You can't locate a HTML element rendered on an ASP page using document.getElementById (not reliably anyway) because the id of the rendered element will not be the same as the id of the ASP control.

E.g. ASP control:

<asp:Button ID="myButton" runat="server />

Renders HTML something like this:

<input type="button" id="namingContainer1_nameContainer2_myButton" />

A more reliable way to get a reference to the required control is to use a jQuery selector:

var grid = $("[id$=PersonGridView]")

This selector returns the element whose id attribute ends with PersonGridView

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.