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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:26:10+00:00 2026-05-17T01:26:10+00:00

This has been covered a couple of times, without a suitable answer: ObjectDataSource firing

  • 0

This has been covered a couple of times, without a suitable answer:

  1. ObjectDataSource firing twice, or on its own
  2. ObjectDataSource created twice when control is changed

I have created a custom paging data class that is used with an ObjectDataSource. In intial tests, I found it was performing worse than my old SqlDataSource code. Whilst investigating, I found that for every page load, the ObjectDataSource is being created and binding twice.

Investigating the links above led me to believe this could be a bug (or unexplained behavior) in regards to changing my GridView’s column visibility in the OnDataBound event like so:

protected void gvContacts_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType != DataControlRowType.Pager && e.Row.Cells[0].Text != gvContacts.EmptyDataText)
    {
        e.Row.Cells[0].Visible = false;
        if (Convert.ToInt16(lstSearchType.SelectedValue) == ADDRESS)
        {
            gvContacts.Columns[2].ItemStyle.Width = Unit.Percentage(30);
            gvContacts.Columns[3].Visible = true;
            gvContacts.Columns[3].ItemStyle.Width = Unit.Percentage(20);
        }
        else
        {
            gvContacts.Columns[2].ItemStyle.Width = Unit.Percentage(50);
            gvContacts.Columns[3].Visible = false;
        }
    }
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes["ID"] = "contact_" + e.Row.Cells[0].Text;
        e.Row.Attributes["onclick"] = "javascript:selectRow($(this).attr('id').replace('contact_',''),2);";
        e.Row.Attributes["ondblclick"] = "javascript:openContact($(this).attr('id').replace('contact_',''),''); selectRow($(this).attr('id').replace('contact_',''),2);";

        //E-mail link
        if (e.Row.Cells[4].Text != " ")
        {
            e.Row.Cells[4].Text = "<a href=\"mailto:" + e.Row.Cells[4].Text + "\">" + e.Row.Cells[4].Text + "</a>";
        }
        //Birthday highlight
        if (e.Row.Cells[6].Text != "&nbsp;")
        {
            DateTime dt = Convert.ToDateTime(e.Row.Cells[6].Text);
            DateTime now = DateTime.Now;
            if (dt.Day == now.Day && dt.Month == now.Month)
            {
                e.Row.Cells[6].BackColor = System.Drawing.Color.FromArgb(255, 230, 160);
            }
        }
    }
}

I use this event to customize the display of certain fields, as well as hide columns that are not applicable during some search types.

When I disable the event, the ODS stops binding twice.

I can’t really think of a way to get around this behavior.

Has anyone else see this issue or developed a work around?

  • 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-17T01:26:10+00:00Added an answer on May 17, 2026 at 1:26 am

    Why do you want to change the visibilty of the columns in the RowDataBound Event? This event will be called for each item that you are binding.

    Hide the colums before you actually perform the DataBind() call on the GridView.

    If this does not help you, you will need to provide the code you use for databinding.

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

Sidebar

Related Questions

It appears this topic has been covered a few times before, but those solutions
Now I realise this topic has been covered many times before. However there did
I know this should be simple and has been covered a million times already
I know this has been covered PLENTY of times but I keep trying different
I know this has been covered many times, but i still can't seem to
I know this has been covered before but I cannot find an answer to
I know this has been covered before, but i can't find exactly what i
Not sure if this has been covered somewhere, but I couldn't find it in
I apologize because I know this has been covered over and over again, but
This topic has been covered on this forums, but I haven't found a working

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.