2

I have Two Labels such as FixedTotal and TotalPercent, One GridView which has One Row such as

    ReferenceID       Percentage          Amount
   --------------    -------------       --------
        1                5                 1000

Here I want to change the "Percentage" Column value 5 with the TotalPercent label's text. and I want to display the "Amount" Column value 1000 in the FixedTotal label. I also want to check whether the Grid has row or not? How to do this? The Columns are BoundField Columns..

2
  • How do you want to initiate the change? Is there a column with an "update" button? Are you trying to add up all of the amounts or use a specific row amount? Commented Jun 9, 2011 at 14:33
  • @Alison: The Percentage in the "TotalPercent" Label may change according to one Button Click event. So the Percentage Specified in the label should replace the Percentage column value in the GridView. By the Percentage the Amount will change and the Amount will be displayed in to the "FixedTotal" Label. Commented Jun 10, 2011 at 4:45

3 Answers 3

3

Getting/Setting value to gridview cells, you need to know the Row Index of Gridview, you can pass row index when you call JS function from gridview

<script language="javascript" type="text/javascript">
function update(rowIndexOfGridview) {
    var ri = rowIndexOfGridview; 
    var grd = document.getElementById('<%= GridView1.ClientID %>');

    CellValue = grd.rows[ri].cells[1].childNodes[0].value; // get
    grd.rows[ri].cells[2].childNodes[0].value = CellValue; assign
    ...........
    .............
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Akhtar, While assigning it shows "The Object does not support this property" and While retrieving it gets "undefined" value.
Follow the answer and try to understand the Javascript first, It should work.
2
<script language="javascript" type="text/javascript"> 
function Calculate() 
<br/>
{ 
<br/>
var grid = document.getElementById("<%=GridID.ClientID%>");
<br/> 
var sum = 0; <br/>
for (var i = 1; i < grid.rows.length; i++)<br/>
 { <br/>
var Cell = grid.rows[i].getElementsByTagName("input"); 
<br/>if (!Cell[4].value) {sum  += 0; } else { sum += parseFloat(Cell[4].value);} } 
<br/>
document.getElementById("<%=TextBox1.ClientID%>").value = sum; 
 }
<br/>
 </script>
------------------------------------------------------------------------



<asp:TemplateField HeaderText="Current payment" >
                            <ItemTemplate>
                                <asp:TextBox ID="cridnvalue" runat="server" Width="70px" BorderStyle="None" onkeyup="CalculateTax();" ></asp:TextBox>
                            </ItemTemplate>
                            <ItemStyle Width="120px" />
                        </asp:TemplateField>

Comments

0

You can try this one. I have used this and has no error.

<script language="javascript" type="text/javascript">
function update(rowIndexOfGridview) {
    var ri = rowIndexOfGridview; 
    var grd = document.getElementById('<%= GridView1.ClientID %>');

    var CellValue = grd.rows[ri].cells[1].childNodes[0].textContent); // get
    grd.rows[ri].cells[2].childNodes[0].textContent = CellValue; //assign
}
</script>

1 Comment

What you did harms all SO users. Read Temporary policy: Generative AI (e.g., ChatGPT) is banned

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.