Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3986924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:04:20+00:00 2026-05-20T06:04:20+00:00

i am stuck with this error since last few hours.. i dont know what

  • 0

i am stuck with this error since last few hours.. i dont know what am i doing wrong here..

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

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

<p> Code Behind : 
protected void PersonGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {

               if (e.Row.RowType == DataControlRowType.DataRow)
            {
         var ID = PersonGridView.DataKeys[e.Row.RowIndex]["ID"].ToString();

                Button btnDetails = (Button)FindControl("Details");
                Button btnModify = (Button)FindControl("Modify");
                Button btnDelete = (Button)FindControl("Delete");
                btnModify.CommandName = "Modify";
                btnDelete.CommandName = "Delete";
                btnDetails.CommandName = "Details";
                btnDelete.CommandArgument = btnModify.CommandArgument = string.Format("{0}", ID);
                btnDetails.Attributes["onclick"] = string.Format("viewProfile({0}); return false;", ID);


            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:04:21+00:00Added an answer on May 20, 2026 at 6:04 am

    Is this the line that’s throwing the error?:

    var ID = PersonGridView.DataKeys[e.Row.RowIndex]["ID"].ToString();
    

    This line is referencing an array item by index in two different places, so you’ll need to do a little debugging to determine which one is the problem. Basically, either PersonGridView.DataKeys[] doesn’t have an index which matches e.Row.RowIndex or that item doesn’t have an index which matches "ID". You’ll need to either step through a debugger to examine those values at runtime or toss in some debugging code (Response.Write statements and such to examine values) to see what’s going on.

    One common error is that the DataGridView is running this code on non-data rows. Header, footer, etc. You can expand the scope of the if statement to address that. Reference the indexes within the conditional rather than outside of it.

    Edit: (In response to your comment below)

    Is btnDetails set to an instance of an object? I’m guessing it isn’t. You’ll need to continue the debugging and see if the control you’re trying to find is actually there. I notice that it’s in a separate ItemTemplate and TemplateField from the other buttons. Is that causing an issue perhaps? I’m not entirely familiar with these server controls so I’m not sure off-hand.

    I should take a moment to point out that your code here is very fragile. The problems you’ve been experiencing are the result of this. You’re referencing arrays by indexes manually, including the use of a “magic string” to reference them. You might want to toss in some error checking for that. You’re also casting and later using objects without checking if they exist first. FindControl can very easily return a null reference, such as when the control isn’t found.

    Throwing in tons of error checking is kind of part of the reality of using these web forms controls and their old data binding methods. A lot of extra code, but that’s how it goes with these controls and directly binding to weakly-typed DataSets and such.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been stuck with this simple Sql query for last 3 hours and my
I am trying to figure out this error since 5 hours without any success.
I being for the last 12 hours trying to understand why this is happening.
note: using django/python/javascript/flash So its been two days since I'm stuck at the error.
I'm kinda stuck with this one so I hoped someone could help me. I
I am stuck on this problem which I am studying for an exam tomorrow.
I'm stuck with this already for some weeks and I don't have the faintest
I have been stuck on this for days, and was wondering if anyone had
I'm kinda stuck on this decision. My project already uses Spring and Spring Blazeds
I've been stuck with this for weeks now and have no idea where I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.