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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:53:21+00:00 2026-05-23T22:53:21+00:00

Q: I have the following problem , and i don’t know how to fix

  • 0

Q:

I have the following problem , and i don’t know how to fix it really.

I have a grid view one of the columns is a template field as (text box). The grid view consists of 8 rows . What i do is every time the user enter data in the text box,I put the total in the last text box(which set enabled = false).I sum the data entry in the text boxes through some method and call it in the event text changed . But every time i enter a number in the text box and then click Tab in the keyboard or use the mouse cursor to move to the next box i lose the focus , and i have to put the mouse cursor again in the intended textbox.

I try the following methods to fix my problem but in vain .

 foreach (GridViewRow r in gv_Evaluation.Rows)
            {
                ((RadTextBox)r.Cells[3].FindControl("txt_evaluateWeights")).Attributes.Add("blur", "calc()");
            }

in my page load , this doesn’t work at all.


protected void txt_evaluateWeights_TextChanged(object sender, EventArgs e)
{
    calc();
    ((TextBox)sender).Focus();
}

This way return the focus to the previous textbox (i mean the one which i already have done) not the text box i wanna the focus in, to enter the data.

EDIT:

My calc method:

private void calc()
        {
            float sum = 0;
            for (int i = 0; i < 7; i++)
            {
                RadTextBox txt1 = (RadTextBox)gv_Evaluation.Rows[i].Cells[3].FindControl("txt_evaluateWeights");
                int weight;
                bool result = Int32.TryParse(txt1.Text, out weight);
                if (result)
                {
                    sum += weight;
                }
            }

            double percentage;
            percentage = Math.Round((sum / 100) * 100, 2);
            RadTextBox txt3 = (RadTextBox)gv_Evaluation.Rows[7].Cells[3].FindControl("txt_evaluateWeights");
            txt3.Text = percentage.ToString();//string.Format("{0:0.0%}", percentage.ToString());

        }
  • 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-23T22:53:22+00:00Added an answer on May 23, 2026 at 10:53 pm

    Doing it using server side PostBack is a horrendous way of doing this.

    Use JavaScript instead. Here is a small example in jQuery

    The GridView

    <asp:GridView ID="DemoGrid" runat="server"
                AutoGenerateColumns="false"
                ShowFooter="true">
        <Columns>
            <asp:TemplateField HeaderText="index">
                <ItemTemplate><%# Container.DataItemIndex + 1 %></ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Item">
                <ItemTemplate>
                    <asp:Label ID="DemoLabel" runat="server" Text='<%# Container.DataItem %>' />
                </ItemTemplate>
                <FooterTemplate>Total</FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Amount">
                <ItemTemplate>
                    <asp:TextBox ID="DemoText" runat="server" CssClass="quantity">
                    </asp:TextBox>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:Label ID="TotalLabel" runat="server" CssClass="result"/>
                </FooterTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    

    The Code Behind

    protected void Page_Load(object sender, EventArgs e){
        if (!IsPostBack)
        {
            string[] array = new string[] { "demo1", "demo2", "demo3", "demo4", "demo5" };
            DemoGrid.DataSource = array;
            DemoGrid.DataBind();
        }
    }
    

    The JavaScript (jQuery)

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".quantity").bind("blur", function () {
                var $quantity = $(this);
                var quantity = +$quantity.val(); //cast to number
                if (!isNaN(quantity)) {
                    var $sum = $quantity.closest("table").find("tr:last .result");
                    var sum = +$sum.html();
                    $sum.html(sum + quantity);
                }
            });
        });
    </script>
    

    Hope this helps

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

Sidebar

Related Questions

I have the following problem: I got a view with two text fields and
Q: I have the following problem : i don't know what the problem i
I have the following problem and don't know how to code it in R:
I 've been set the following problem and don't have a clue how to
I am having a strange problem which I don't understand. I have the following
I'm facing the following problem and don't have an answer to it: We have
I have the following problem: in a database table are Sales recorded. One of
I have the following problem: Multithreaded WPF application, Model View Presenter Implementation. Presenters and
I have the following problem with QT model/view framework. I want to render a
I have following problem: I display an HTML-Document with an JTextPane. In my HTML-Text

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.