Code
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Alpesh ManiyaRank #832 · 2.7K reputationPosted Jan 19, 2024, 6:33 AM EST
To compare the values in the "Amount1" and "Amount2" columns of a GridView and display the greater amount in the "Greater Amount" column, you can achieve this by using the
RowDataBoundevent in the code-behind file of your ASP.NET page. Here'sprotected void GridViewExample_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // Access the textboxes and label within the row TextBox txtAmount1 = (TextBox)e.Row.FindControl("txtAmount1"); TextBox txtAmount2 = (TextBox)e.Row.FindControl("txtAmount2"); Label lblAmount = (Label)e.Row.FindControl("lblAmount"); // Compare the values and set the label text decimal amount1 = decimal.Parse(txtAmount1.Text); decimal amount2 = decimal.Parse(txtAmount2.Text); lblAmount.Text = amount1 > amount2 ? amount1.ToString() : amount2.ToString(); } }Sandeep KumarRank #1,642 · 937 reputationPosted Jan 19, 2024, 6:40 AM EST
amount1 and amount 2 user will input
Sachin SinghRank #66 · 26.2K reputationPosted Jan 19, 2024, 6:51 AM EST
you can use this
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { TextBox txtAmount1 = (TextBox)e.Row.FindControl("txtAmount1"); TextBox txtAmount2 = (TextBox)e.Row.FindControl("txtAmount2"); Label lblAmount = (Label)e.Row.FindControl("lblAmount"); // Assuming the amounts are decimal values if (decimal.TryParse(txtAmount1.Text, out decimal amount1) && decimal.TryParse(txtAmount2.Text, out decimal amount2)) { // Compare the amounts and set the text of lblAmount lblAmount.Text = (amount1 > amount2) ? amount1.ToString() : amount2.ToString(); } else { // Handle invalid input if needed lblAmount.Text = "Invalid input"; } } }Sam HobbsRank #107 · 20.5K reputationPosted Jan 19, 2024, 1:28 PM EST
You do not show where the data is coming from. I assume there is a list (or something like a list) of classes with
Amount1andAmount2as members. It can also have a member for the result of the comparison. Then when the list is loaded process it to do the comparisons.Sandeep KumarRank #1,642 · 937 reputationPosted Jan 20, 2024, 12:27 AM EST
few column data comming from database after binding grid few column are iput column then i willsave data to another database table