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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:16:18+00:00 2026-05-28T14:16:18+00:00

Where I work there is a page with two grid views and both gridviews

  • 0

Where I work there is a page with two grid views and both gridviews use the same binding function and there is a problem because of it.. so in the function it has a foreach row for the gridview but it only does it for one gridview as you will see in the code, how can I make it so that it iterates throw the gridviews in the page? therea are two one named GridView1 and the other GridView2, but both use the same data bind. I want to reduce the code.. see below:

protected void GridView_DataBound(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
             //somecode related to GridView1
        }

        foreach (GridViewRow row in GridView2.Rows)
        {
            //somecode related to GeidView2
        }
      }

Now the code in each foreach is extensive, and basically is the same code for both cases.. how can i do this more efficiently instead of having the same code in the foreach’s for each one of the gridviews?

  • 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-28T14:16:18+00:00Added an answer on May 28, 2026 at 2:16 pm

    Just use the sender object that is passed to the event handler. This is a reference to the object that raised the event.

    protected void GridView_DataBound(object sender, EventArgs e) 
    {
        GridView CurrentGv = (GridView)sender;
    
        foreach (GridViewRow row in CurrentGv.Rows) 
        { 
             //somecode related to BOTH GridViews
        } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My page has two 'tabbed' navigation sections. Both independent of one-another, but resulting in
I've two updatepanel in the same page. In one, there is a datalist while
There are two grid at my page. When a row is clicked at first
Is there a way to make a certain page work as a cookieless session?
I'm looking into a solution for work, where you have a two page spread
I'm trying to create a page where there are two dropdown menus, and then
as stated both of these do not work (from Page_Load ): Textbox1.Focus(); or Page.SetFocus(Textbox1);
Our page loads two external pages (same url) using $(#div1).load(mypageurl) & $(#div2).load(mypageurl). Each div
I have a page with two ContentPlaceHolders. One has a DropDown and another UpdatePanel
i have a page where there are two links to pdf files. the first

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.