开发者

javaScript Function

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>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜