[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

formula for GRIDVIEW CONTROLS

Posted on 2009-04-15
2
Medium Priority
?
1,053 Views
Last Modified: 2012-05-06
Following are the two bound textboxes in the gridview:

First Textbox:
<EditItemTemplate>
<asp:TextBox ID="TextBox12" runat="server" Text='<%# Eval("PAYMENT_AMOUNT") %>'></asp:TextBox>
</EditItemTemplate>

Second Textbox:

 <EditItemTemplate>
 <asp:TextBox ID="txt11" runat="server" Text='<%# Eval("PRINCIPAL_AMOUNT") >'></asp:TextBox>
</EditItemTemplate>

Not bound Textbox:

 <EditItemTemplate>
                    <asp:TextBox ID="txt6" runat="server" Text=></asp:TextBox>
</EditItemTemplate>

The First Question is how can i take the difference of first two text boxes in the third textbox (i.e;  PRINCIPAL_AMOUNT-     PAYMENT_AMOUNT).
Should i write like this :    

<EditItemTemplate>
                    <asp:TextBox ID="txt6" runat="server" Text=></asp:TextBox = PRINCIPAL_AMOUNT-     PAYMENT_AMOUNT>
</EditItemTemplate>      

Second question is how can i make the client side event of textbox leave? What i want is when the cursor leaves the first or second textbox, third textbox should automatically be updated with the above formula.


Please suggest.              
0
Comment
Question by:salmanfazal
2 Comments
 
LVL 3

Expert Comment

by:OneMHz
ID: 24151405
For question 1, you could do something like <%# Eval("PRINCIPAL_AMOUNT") - Eval("PAYMENT_AMOUNT") > as long as they're both numeric types, or Convert.ToDecimal(Eval("PRINCIPAL_AMOUNT")) - Convert.ToDecimal(Eval("PAYMENT_AMOUNT")) if they're not.  You could also create a function in your codebehind like protected string GetBalance() that returns the difference, formatted however you want, then just use <%# GetBalance() %> in your textbox declaration.

For question 2, you'll need to first write a javascript function to do the calculation, then in the Page_Load event, use TextBox12.Attributes.Add("onchange", "calculateBalance();");  assuming you called the javascript function calculateBalance.  That will add an onchange event handler to the output control, which will fire when the value of the textbox has changed and the focus leaves the control.  It will not fire if focus leaves the control with the same value.
0
 

Accepted Solution

by:
salmanfazal earned 0 total points
ID: 24155410
i tried the first question and the error comes like this: Operator '-' is not defined for type 'DBNull' and type 'DBNull'. in both the fields there is no null values. if its empty the value is 0. what could be the reason behind this.
below is my code part getting error.

<asp:TemplateField HeaderText="Inst. Balance">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox9" runat="server" text ='<%#Eval("PRINCIPAL_AMOUNT")-Eval("PAYMENT_AMOUNT")%>' ></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label21" runat="server" text ='<%#Eval("PRINCIPAL_AMOUNT")-Eval("PAYMENT_AMOUNT")%>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question