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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:14:52+00:00 2026-06-15T03:14:52+00:00

I have a situation where I have Multiple GridViews on a page GridView1 –

  • 0

I have a situation where I have Multiple GridViews on a page GridView1 – GridView4.
All these GridViews have TextBoxes in the cells, I would like to run a calculation function only on the Column of the TextBox that was Clicked and on that particular GridView.

Example: A user clicks on a TextBox in Column 2 of GridView3 and changes a number value, the OnTextChange event of that particular TextBox should fire to run a calculation and total all the numbers of GridView3 Col2 in a footer label.

I searched and all the other suggestions I found assume you have only 1 grid and that you know what preset Column the calculation is done at IE a prices column, But I don’t know what Column info a user will edit in any of my 4 GridViews.

I gave up and resolved to just running the calculation code on the Entire GridView, not just the column edited, but to do this I need to Get the GridView.ID of the Gridview containing the TextBox. Extensive serches came up with how to get the ID of the sender Item but not the GridView.ID that contains the sender.

If anyone can help with either situation, please do so, I would really appreciate it.

As Per the conversations below, I have edited this post to include the Edited answer provided by Tim in the hopes that others may learn from this code:

//This is working code
protected void textBox_TextChanged(Object sender, EventArgs e)
{
    TextBox txt = (TextBox)sender;
    GridViewRow gvRow = (GridViewRow)txt.NamingContainer;
    GridView Grid = (GridView)gvRow.NamingContainer;

    // if you need the index of the column of the TextBox
    int colIndex = 0;
    for (int i = 0; i < gvRow.Cells.Count; i++)
    {
        if (gvRow.Cells[i] == txt.Parent)
        {
            colIndex = i;
            Msg.Text = "Col: "+colIndex.ToString();
            break;
        }
    }

    int gridNum = 0;
    switch (Grid.ID)
    {
        case "GridView1":
            gridNum = 1;
            break;

        case "GridView2":
            gridNum = 2;
            break;

        case "GridView3":
            gridNum = 3;
            break;

        case "GridView4":
            gridNum = 4;
            break;
    }

    Label ColTotal = (Label)Grid.FooterRow.FindControl("G" + gridNum + "TotalPP" + colIndex);

    double total = 0;
    foreach (GridViewRow row in Grid.Rows)
    {
        TextBox tb = (TextBox)row.FindControl(txt.ID);
        double d;
        if (double.TryParse(tb.Text, out d))
            total += d;
    }
    ColTotal.Text = total.ToString(); 
}

As you can see, according to the way the code is set up, the colIndex will help me find the footer label for each column and put it’s total in.

  • 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-15T03:14:54+00:00Added an answer on June 15, 2026 at 3:14 am

    You could let all TextBoxes handle the same TextChanged event and use this (untested) code:

    protected void textBox_TextChanged(Object sender, EventArgs e)
    {
        TextBox txt = (TextBox) sender;
        GridViewRow gvRow = (GridViewRow) txt.NamingContainer;
        GridView gv = (GridView) gvRow.NamingContainer;
        // if you need the index of the column of the TextBox
        // as commented below you're using .NET 2.0
        int colIndex;
        for (int i = 0; i < gvRow.Cells.Count; i++)
        {
            if (gvRow.Cells[i] == txt.Parent)
            {
                colIndex = i;
                break;
            }
        }
    
        double total = 0;
        foreach (GridViewRow row in gv.Rows)
        {
            TextBox tb = (TextBox)row.FindControl(txt.ID);
            double d;
            if (double.TryParse(tb.Text, out d))
                total += d;
        }
        var tbFooter = (TextBox) gv.FooterRow.FindControl(txt.ID);
        tbFooter.Text = total.ToString();
    }
    

    Of course assuming that all TextBoxes are in TemplateFields and the footer TextBox has the same ID. Remember to set AutoPostback to true if you want to postback immediately.

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

Sidebar

Related Questions

I have a situation where I want to run multiple EventMachines in Ruby -
I have a situation where I need to connect multiple DBs to get all
I have the following situation: multiple virtual directories under same application pool in IIS
The situation: I have multiple classes that should each hold a variable with a
I have a situation where I return results with multiple rows. I'm looking for
I have a situation where a Java Applet hangs after being opened multiple times.
I have the following situation: An Conversations entity/table which has multiple Tags associated to
I have a simple parent-child situation where the parent can have multiple children. The
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation where I have to handle multiple live UDP streams in the

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.