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 477929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:38:25+00:00 2026-05-13T00:38:25+00:00

This is a Master-Detail form. Master is a GridView. And, the Detail is a

  • 0

This is a Master-Detail form. Master is a GridView. And, the Detail is a DetailsView.

The entire thing is achieved programmatically.

As you can see from the code, DetailsView is using the Master-objects’s ID to retrieve the Detail items.

I need to make the ID column of the Master-GridView invisible. Coz, it is irrelevent for the user of the page. But it must not harm the page logic.

But the code-line, GridView1.Columns[1].Visible = false; is generating an exception.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

How should I solve this problem?

public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        protected void BindData()
        {
            List<Order> orders = Order.Get();

            GridView1.DataSource = orders;
            GridView1.DataBind();

            // This is giving Error...............!!!
            GridView1.Columns[1].Visible = false;

            // At first, when the page first loads, 
            //      GridView1.SelectedIndex == -1
            // So, this is done to automatically select the 1st item.
            if (GridView1.SelectedIndex < 0)
            {
                GridView1.SelectedIndex = 0;
            }

            int selRowIndex = GridView1.SelectedIndex;

            int selMasterId = Convert.ToInt32(GridView1.Rows[selRowIndex].Cells[1].Text);

            Order master = Order.Get(selMasterId);

            labItemsCount.Text = master.Items.Count.ToString();

            DetailsView1.DataSource = master.Items;
            DetailsView1.DataBind();            
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
        {
            DetailsView1.PageIndex = e.NewPageIndex;

            BindData();
        }
    }

alt text

  • 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-13T00:38:25+00:00Added an answer on May 13, 2026 at 12:38 am

    Have you considered using the DataKeyNames property of the gridview? This way you can remove the ‘id’ column from the GridView bu still access the ‘id’ value in the Page_Load.

    DataKeyNames = "id"
    

    Then you can get the value of the id like this.

    int selRowIndex = GridView1.SelectedIndex;
    int selMasterId = Convert.ToInt32(GridView.DataKeys[selRowIndex].Value);
    Order master = Order.Get(selMasterId);
    

    Alternately, you could try changing the visibility of the column in the OnRowBound event of the GridView.

    protected void GridView_RowDataBound(object sender,   GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header ||
            e.Row.RowType == DataControlRowType.DataRow ||
            e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[1].Visible = false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a master detail form using the wizard. I can get LOV selects
This is my class Record which can be master/detail/details Records of teachers and their
my structure is like this: master page aspx(web form) ascx(user control) I have a
I know we've done this before in another .aspx page that's using this master
I have 2 master pages that are nested.this is main master page code for
I have a form that calculates a total number using Javascript. The code for
I've got a gridview/formview, master/detail relationship going on. When I click a button in
I'm trying to create a kind of master/detail UI using an MVP pattern. I
I want to show a master / detail relationship using two datagridviews and DataRelation
actually I'm developing a template using ASP.net and C#. as you can see below

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.