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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:34:13+00:00 2026-06-11T04:34:13+00:00

Currently I have few methods that accept GridView object as parameter and the value

  • 0

Currently I have few methods that accept GridView object as parameter and the value within the GridView object is being accessed to perform calculation.

My question is whether this is a good practice? I notice that when I need to change the result display (i.e. the GridView will have a result of 9 cells rather than 10 cells originally), I would need to change all the methods that uses it or risk getting an ArrayIndexOutOfBound error.

Example

public static string checkCount(GridView gr)
{
     //need to change the cell index if the sql to get the gridview is changed
     string name = gr.Rows[b].Cells[9].Text.ToUpper(); 
}

Any thoughts on this?

Thanks

EDIT
Is it better to have a method that put map the sql result into a list of object, where the object itself is a representation of the data row. This way even if i remove a column, i just need to deal with the mapping method itself, others should be functioning as per norm.

Example:

public class Profile{
    string name {get;set;}
    string icNo {get;set;}
}

public list getProfileList(){
    //run some query here and loop the result
    //while looping
    profile = new Profile(name=/*the name result*/, icNo=/*icNo from result*/ );
    //return the list
}

Page Load

List profiles = getProfileList();
gv.DataSource = profiles;
gv.DataBind();


public string calculationMethod(List profiles){
    //when in need of the result, just get the object from profiles and process
}
  • 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-06-11T04:34:14+00:00Added an answer on June 11, 2026 at 4:34 am

    object as parameter and the value within the GridView object is being accessed to perform calculation

    From where do the values come? I think a better practice would be to perform the calculations directly on your data/business object or a helper object which is responsible for only this specific calculation. Then you could have another function which dynamically creates the result view from this helper object instead of your BO or whatever.

    will have a result of 9 cells rather than 10 cells originally

    This is exactly why you should work not directly with the cells for calculation. And if you really need to do it, so you should look for another way to find the indices for the calculation. They could depend on the actual result object. (In which your values can be present also in the specific data type; only for visualization and user input the should converted to string or some-like)

    In generell to solve this problem you should analyse clearly what are your needs. Keep some things like:

    • http://en.wikipedia.org/wiki/Single_responsibility_principle
    • http://en.wikipedia.org/wiki/Separation_of_concerns

    Also may think of using n-Tier model for your application

    • http://en.wikipedia.org/wiki/Multitier_architecture
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have an asp:GridView that displays a few BoundFields and then one asp:TemplateField
I currently have a python script that runs every few minutes and picks up
Currently I have a simple knockoutJS object, with a few observables. But this object
We have quite a few validation methods that need to access repositories / database
Is it possible to have a single WSDL exposing few methods that must be
I'm using Moose to write an object module. I currently have a few mandatory
We currently have a few products for which the licensing depends on the computer
I currently have event.stopPropagation() to work on a few selectors, but now I need
Currently, I have a few hundred image files, hosted in Google Drive. I wish
I'm currently using Look&Feel for my application. I have a few problems: 1. When

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.